卸载系统自带mariadb数据库
# rpm -qa| grep mariadb
# rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64
下载YUM库
# rpm wgethttp://dev.MySQL.com/get/mysql57-community-release-el7-7.noarch.rpm
安装YUM库
# rpm yum localinstall -ymysql57-community-release-el7-7.noarch.rpm
安装数据库
# rpm yum install -y mysql-community-server
启动MySQL服务
# rpm systemctl start mysqld.service
由于mysql5.7会自动生成密码,密码文件存储在/var/log/mysqld.log 中搜索password关键字即可找到密码,登陆mysql
# mysql -uroot -p
重置root用户密码
mysql > alter user 'root'@'localhost' identified by '密码';
重新以root用户和刚设置的密码进行登录即可。并授权用户root使用密码从任何主机连接到mysql服务器
mysql > grant all privileges on *.* to 'root'@'%' identifiedby '密码' with grant option;
mysql > flush privileges;
或允许用户root只能从ip为192.168.1.1的主机连接到mysql服务器
mysql > grant all privileges on *.* to 'root'@'192.168.1.1' identified by '密码' with grant option;
mysql > flush privileges;
开启3306端口
# firewall-cmd --add-port=3306/tcp