1、先删除mariadb
[root@tjtxxh01 devops]# rpm -qa|grep mariadb
mariadb-libs-5.5.65-1.el7.x86_64
[root@tjtxxh01 devops]# rpm -e --nodeps mariadb-libs-5.5.65-1.el7.x86_64
[root@tjtxxh01 devops]# rpm -qa|grep mariadb
2、centos的yum 源中默认是没有mysql的,所以我们需要先去官网下载mysql的repo源并安装。
wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
#本地安装mysql的yum源
yum localinstall mysql80-community-release-el7-1.noarch.rpm
#查看/etc/yum.repos.d/路径下多了mysql文件
ll /etc/yum.repos.d/ |grep mysql
#yum源
yum clean all
yum makecache
#查看yum中mysql版本
yum repolist all | grep mysql
3、安装mysql
#安装mysql
yum install mysql-community-server
#启动
systemctl start mysqld.service
#设置开机自启动
systemctl enable mysqld.service
#停止
systemctl stop mysqld.service
#重启
systemctl restart mysqld.service
4、登录mysql
mysql在安装后会创建一个root@locahost账户,并且把初始的密码放到了/var/log/mysqld.log文件中;
cat /var/log/mysqld.log | grep password
# 使用初始密码登录
mysql -uroot -p
5、修改密码
alter user 'root'@'localhost' identified with mysql_native_password BY '12345678';
flush privileges
6、my.cnf配置文件
cd /etc/my.cnf
7、开启远程访问
use mysql;
# 查询能访问的host,默认只能localhost访问
select user,authentication_string,host from user;
# 修改root用户能够任何IP访问,当然也能制定具体某个IP
update user set host = '%' where user = 'root';
flush privileges;
另外还需要打开服务器防火墙,把mysql端口放开,要不然公网IP也访问不到服务器的mysql端口
# 查询防火墙状态
systemctl status firewalld
# 启动
systemctl start firewalld
# 关闭
systemctl stop firewalld
# 查看已开启端口
firewall-cmd --list-port
# 开启端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
# 重启
firewall-cmd --reload