Centos7 安装 MySql 8.0

/ 工具插件

centos7 安装 mysql 8

1. 移除 mariadb

- rpm ‐qa | grep mariadb 
- yum remove mariadb*

2. 安装 mySql

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

3. 配置 my.cnf

- 配置 my.cnf
- vim /etc/my.cnf
- [client]
- default-character-set=utf8
- [mysql]
- default-character-set=utf8
- [mysqld]
- init-connect='SET NAMES utf8'
- character-set-server=utf8
- 不区分大小写
- lower_case_table_names=1
- server接受的数据包大小
- max_allowed_packet = 4M
- 默认引擎
- default-storage-engine=InnoDB
- 默认使用  mysql_native_password  认证
- default_authentication_plugin=mysql_native_password
- datadir=/opt/data_mysql
- socket=/var/lib/mysql/mysql.sock
- 关闭数据分区储存
- symbolic-links=0
- log-error=/var/log/mysqld.log
- pid-file=/var/run/mysqld/mysqld.pid

4. 启动 mysql 服务

- systemctl enable mysqld
- systemctl start mysqld

5. 初始化 mysql

- 初始化 mysql
- mysqld --initialize --datadir=/opt/data_mysql

6. 重置密码

- 初始化 mysql
- 查找 root 初始密码
- cat /var/log/mysqld.log
- 设置新的 root 密码
- mysql -u root -p
- ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'P@ssw0rd';

7. 开启远程访问

- use mysql;
- update user set host = '%' where user = 'root';
- FLUSH PRIVILEGES;