CentOS 安装 MySQL 8.0

640 阅读1分钟

前言

CentOS 版本:

$ cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

开始之前请务必将系统更新

$ yum update -y

1.下载

$ wget https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
$ yum install mysql80-community-release-el7-3.noarch.rpm -y

2. 安装 MySQL Server

$ yum install mysql-community-server -f

3. 使用前的一些准备工作

3.1 启动 MySQL Server

$ systemctl start mysqld

3.2 修改密码

3.2.1 查看初始密码

$ cat /var/log/mysqld.log

输出如下:

2019-07-13T04:43:51.251982Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.16) initializing of server in progress as process 30629
2019-07-13T04:43:54.473795Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ;pcSFq7)5S#h
2019-07-13T04:43:55.704693Z 0 [System] [MY-013170] [Server] /usr/sbin/mysqld (mysqld 8.0.16) initializing of server has completed
2019-07-13T04:43:57.613183Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.16) starting as process 30676
2019-07-13T04:43:58.194311Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2019-07-13T04:43:58.237766Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.16'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server - GPL.
2019-07-13T04:43:58.283575Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060

第二行就是初始密码:;pcSFq7)5S#h

3.2.2 修改密码

利用初始密码连接 MySQL

$ mysql -u root -p

修改密码

mysql> ALTER user 'root'@'localhost' IDENTIFIED BY 'password';

4. 允许远程访问

mysql> CREATE USER 'root'@'%' IDENTIFIED BY 'password';
mysql> GRANT ALL ON *.* TO 'root'@'%';
mysql> FLUSH PRIVILEGES;

Navicat 无法访问的解决方法:

mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password';