Centos8 安装mysql5.7

HUC-WFX 8月前 ⋅ 405 阅读

1、添加MySQL5.7仓库 关闭Centos8中MySQL默认的AppStream仓库:

sudo dnf remove @mysql
sudo dnf module reset mysql && sudo dnf module disable mysql
目前还没有EL8版本的MySQL仓库,所以我们这里用EL7的代替,创建一个新的仓库文件:
sudo vi /etc/yum.repos.d/mysql-community.repo

然后将以下内容粘贴到新建的仓库文件中:

[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=0

[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/
enabled=1
gpgcheck=0

[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch/
enabled=1
gpgcheck=0

2:开始安装MySQL5.7 但步骤1的仓库文件创建完成后,就可以通过以下的命令在centos8中安装MySQL5.7了:

sudo dnf --enablerepo=mysql57-community install mysql-community-server

输入Y开始安装 3:自动启动和安全配置 但第一次安装好MySQL5.7后,需要开启服务,实现重启自动启动:

sudo systemctl enable --now mysqld.service

然后获取mysql初始密码,用于后续安装配置操作
grep 'A temporary password' /var/log/mysqld.log |tail -1

接着开始对mysql进行安全配置,通过MySQL Secure Installation去修改密码、关闭root远程登陆权限,、删除匿名用户、删除测试数据库等:
sudo mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root:


Set root password? [Y/n]
是否设置root用户的密码 (y【设置登录密码】)
Remove anonymous users? [Y/n]
是否删除匿名用户 (y)
Disallow root login remotely? [Y/n]
是否禁止root远程登录 (n)
Remove test database and access to it? [Y/n]
是否删除test数据库(y)
Reload privilege tables now? [Y/n]
是否重新加载授权信息 (y)

2-2、配置远程登陆参数
mysql -uroot -p
# 授权(root用户)远程连接权限(不建议)
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '远程登录密码' WITH GRANT OPTION;
FLUSH PRIVILEGES;
# 使用单独的远程登录用户(推荐)
GRANT ALL PRIVILEGES ON *.* TO '新用户名'@'%' IDENTIFIED BY '远程登录密码' WITH GRANT OPTION;
FLUSH PRIVILEGES;