Redhat7.6安装MySQL8.0.23——二进制安装
操作系统版本:Red Hat Enterprise Linux 7.6
MySQL版本:mysql-8.0.23-el7-x86_64.tar.gz
groupadd mysql
useradd -g mysql mysql
echo 'mysql:mysql' | chpasswd
cd /usr/local/
tar -zxvf mysql-8.0.23-el7-x86_64.tar.gz
mv mysql-8.0.23-el7-x86_64 mysql
chown -R mysql:mysql mysql
cd mysql
初始化:
vi /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /data
log_error = /data/mysql-error.log
port = 3306
socket = /data/mysqld.sock
pid_file = /data/mysqld.pid
character-set-server=utf8
lower_case_table_names=1
max_connections=1000
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'
[mysql]
default-character-set=utf8
[client]
default-character-set=utf8
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data
[root@mysql data]# more mysql-error.log
2021-04-15T02:39:36.209816Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.23) initializing of server in progress as process 12748
2021-04-15T02:39:36.212809Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for
UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2021-04-15T02:39:36.231253Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-04-15T02:39:37.003852Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-04-15T02:39:38.780676Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 3dpGwPtaR5*>
mysql启动服务:
vi /etc/systemd/system/mysqld.service
内容如下:(缺点:当kill掉时,无法自动启动恢复)
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
Documentation=https://www.freedesktop.org/software/systemd/man/systemd.unit.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
LimitNOFILE = 5000
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
systemctl start mysqld.service
systemctl status mysqld.service
配置环境变量:
vi /etc/profile
追加内容如下:
MYSQL_HOME=/usr/local/mysql
export PATH=.:$PATH:$MYSQL_HOME/bin
修改root初始密码:
ln -s /data/mysqld.sock /tmp/mysql.sock
这样就不用在登陆的时候指定sock文件了
mysql -u root -p
3dpGwPtaR5*>
alter user root@'localhost' identified by 'root';
flush privileges;
配置mysql远程登录:
关闭防火墙或开放MySQL端口
查看允许访问MySQL的用户和地址
select user,host from mysql.user;
create user 'root'@'%' identified by 'root';
grant all privileges on *.* to 'root'@'%';
flush privileges;
--------------------------------------------------------------------------
在使用 Navicat for Mysql连接mysql 8.0时会报如下错误:
mysql> authentication plugin 'caching_sha2_password' cannot be loaded;
mysql8.0 引入了新特性 caching_sha2_password;这种密码加密方式客户端不支持;客户端支持的是mysql_native_password 这种加密方式;
我们可可以查看mysql 数据库中user表的 plugin字段;
mysql> use mysql;
mysql> select user,plugin from user where user='root';
+------+-----------------------+
| user | plugin |
+------+-----------------------+
| root | caching_sha2_password |
| root | caching_sha2_password |
+------+-----------------------+
2 rows in set (0.00 sec)
可以使用命令将他修改成mysql_native_password加密模式
alter user 'root'@'%' identified with mysql_native_password by 'root';
select host,user,plugin from user;