Centos7.9安装mysql8

69 阅读1分钟

1、先下载安装包

dev.mysql.com/downloads/m…

image.png

centos7选这个,其他版本自己对着选

image.png

2、安装

我这里是/usr/local/mysql

解压文件

tar -xvf mysql-8.0.42-1.el7.x86_64.rpm-bundle.tar

安装

yum localinstall -y mysql-community-*.rpm

启动服务

systemctl start mysqld
systemctl enable mysqld

3、配置

获取临时密码

grep 'temporary password' /var/log/mysqld.log

重置安全设置

mysql_secure_installation

安全配置解释

$ mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: [输入临时密码]

# 1. 密码强度插件
Would you like to setup VALIDATE PASSWORD component? Y
There are three levels of password validation policy:
0 = LOW | 1 = MEDIUM | 2 = STRONG
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2

# 2. 更改root密码
Please set the password for root here.
New password: [输入强密码]
Re-enter new password: [重复强密码]

# 3. 移除匿名用户
Remove anonymous users? Y

# 4. 禁止root远程登录
Disallow root login remotely? Y

# 5. 移除测试数据库
Remove test database and access to it? Y

# 6. 重载权限
Reload privilege tables now? Y

All done!

修改配置文件vim /etc/my.cnf

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

bind-address = 0.0.0.0
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
default_authentication_plugin=mysql_native_password

重启让配置生效 systemctl restart mysqld

4、远程访问

CREATE USER 'admin'@'%' IDENTIFIED BY '强密码';
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
SELECT user, host FROM mysql.user;