centos7的yum源中没有mysql安装包。
先在linux中安装wget的命令
yum install wget
再使用wget获取网络上的mysql安装包
wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
需要放置到本地仓库中
rpm -ivh mysql57-community-release-el7-9.noarch.rpm进入仓库运行安装mysql的代码
cd /etc/yum.repos.d/
yum -y install mysql-server
安装报错,提示无公共秘钥
解决方法:
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
然后再次安装
启动mysql服务
systemctl start mysqld.service
查看临时密码
grep 'temporary password' /var/log/mysqld.log
登录mysql
mysql -uroot -p
设置密码策略为低
set global validate_password_policy=LOW;
设置密码
set password for root@localhost = password('aaa123') ;
给防火墙加白名单,放开3306端口。或者关闭防火墙。
设置远程访问权限
grant all privileges on . to root@'%' identified by 'aaa123';
flush privileges;