Linux centos 7安装 MySQL5.7
参考 https://blog.csdn.net/qq_35526165/article/details/103157274
1. 下载rpm文件
wget https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm
截图:
2. 安装rpm
rpm -ivh mysql57-community-release-el7-11.noarch.rpm
截图:
需要确认的时候请按y,安装完成后在/etc/yum.repos.d目录将新增mysql-community.repo和mysql-community-source.repo
3. 安装mysql
yum install mysql-community-server
截图:
4. 启动MySQL服务
systemctl start mysqld
截图:
5. 设置mysql开机启动
systemctl enable mysqld
systemctl daemon-reload
截图:
6. 查找root密码
mysql安装完成之后,在/var/log/mysqld.log文件中为root用户生成默认密码。
grep 'temporary password' /var/log/mysqld.log
截图:
7. 登录mysql
mysql -u root -p 默认密码
截图:
8. 修改登录密码
set password for 'root'@'localhost'=password('新密码');
截图:
补充:
密码的格式【大小写字母+数字+特殊符号】
9. 修改配置文件
vi /etc/my.cnf
配置修改如下:
[mysqld]
character_set_server=utf8
init_connect=’SET NAMES utf8’
截图:
10. 重启mysql
systemctl restart mysqld
截图:
11. 开启远程访问
授权
按顺序执行如下代码
create user 'root'@'%' identified with mysql_native_password by '远程访问的密码';
grant all privileges on *.* to 'root'@'%' with grant option;
flush privileges;
截图:
开放端口
退出MySQL后,依次输入下列三行代码
firewall-cmd --zone=public --add-port=3306/tcp --permanent
systemctl restart firewalld.service
firewall-cmd --reload
截图:
12. 测试连接
连接成功
截图: