查看系统是否预装了mariadb,进行卸载操作
rpm -qa|grep mari
查看出现的版本,例如
rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
开始安装mysql,下载rpm包
wget -c https://dev.mysql.com/get/mysql80-community-release-el7-7.noarch.rpm
下载完后运行安装
rpm -ivh mysql80-community-release-el7-7.noarch.rpm
yum -y install mysql-server
查看mysql状态
systemctl status mysqld
启动
systemctl start mysqld
开机自启
systemctl enable mysqld
获取mysql初始密码
grep 'temporary password' /var/log/mysqld.log
输入mysql -u root -p登录MySQL
mysql -u root -p
密码为上面查询的初始密码
选中mysql数据库
use mysql;
如果已经是myql 就不用切换
修改初始密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'aAbBcCdD/*-+';
修改库中的user表中,user用户的host=% (任意连接)
use mysql;
update user set host='%' where user ='root';
重新加载权限表
flush privileges;
给与root用户赋予远程连接权限
grant all privileges on *.* to 'root'@'%' with grant option;
# 赋子权限并修改密码
alter user 'root'@'%' identified with mysql_native_password by 'aAbBcCdD/*-+';
刷新权限
flush privileges;
开放端口 3306