一、安装 MySQL 5.7 版本的软件源
https://dev.mysql.com/downloads/repo/yum/
rpm -Uvh https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
二、用yum安装
然后使用yum命令安装mysql服务器
在这里要注意:必须进入到 /etc/yum.repos.d/目录后再执行以下脚本
yum安装mysql服务
三、遇到的坑
1、mysql-community-server-5.7.44-1.el7.x86_64.rpm 的公钥尚未安装
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
2、mysql --initialize specified but the data directory has files in it. Abortin
网上说是由于MySQL数据目录中已经存在文件而导致的,要删除已经存在的目录文件。但是我删除之后还是存在,解决不了我所遇到的问题,所以我是直接删除已下载的,重新来一遍。
四、启动服务
systemctl start mysqld
五、获取安装时的临时密码(在第一次登录时就是用这个密码)
grep 'temporary password' /var/log/mysqld.log
或
grep 'temporary password' /var/log/msyql/mysqld.log
五、登录,输入刚才获得的密码
mysql -u root -p
六、重置密码
在更改之前,先刷新一下
FLUSH PRIVILEGES;
更改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
设置数据库,设置可以远程登录
use mysql;
update user set Host='%' where User='root';
最后在刷新一下,退出
FLUSH PRIVILEGES;
exit;
七:navicat 连接 阿里云 服务器
修改阿里云安全组
修改系统中配置文件
1.cd /etc/mysql/mysql.conf.d
2.vi mysqld.cnf
##进入文件后开启编辑模式(i),将bind-address注释或者改为0.0.0.0
进入控制台重启
systemctl restart mysql #重启mysql服务器命令
systemctl start mysql #启动mysql服务器命令
systemctl status mysql #查看mysql服务器状态命令
八、测试连接