1.查找系统是否安装mariadb(一般系统有自动)# rpm -qa | grep mariadb
2.有显示,卸载mariadb # rpm -e --nodeps mariadb-libs-5.*
3.上传mysql所需要的安装吧
mysql-community-client-5.7.21-1.el7.x86_64.rpm
mysql-community-common-5.7.21-1.el7.x86_64.rpm
mysql-community-libs-5.7.21-1.el7.x86_64.rpm
mysql-community-server-5.7.21-1.el7.x86_64.rpm
4.common libs client server 逐一安装
# rpm -ivh mysql-community-common-5.7.21-1.el7.x86_64.rpm
# rpm -ivh mysql-community-libs-5.7.21-1.el7.x86_64.rpm
# rpm -ivh mysql-community-client-5.7.21-1.el7.x86_64.rpm
5.当安装mysql-server 会提示
错误:依赖检测失败:
/usr/bin/perl 被 mysql-community-server-5.7.21-1.el7.x86_64 需要
perl(Getopt::Long) 被 mysql-community-server-5.7.21-1.el7.x86_64 需要
perl(strict) 被 mysql-community-server-5.7.21-1.el7.x86_64 需要
6.安装/usr/bin/perl等mysql-server的依赖文件
# yum install perl
# yum install libaio
# yum install cyrus-sasl-lib
# rpm -ivh mysql-community-server-5.7.21-1.el7.x86_64.rpm
7.修改mysql执行文件权限并启动mysql
#chown -R 777/var/lib/mysql
#service mysqld start
8.配置与修改密码(不修改密码,mysql用不了)
使用rpm方式安装,系统默认分配一个临时密码
8.1输入 # cat /etc/my.cnf
查看mysql的配置
my.cnf配置文件中有查找log文件的路径,可以看到
log-error=/var/log/mysqld.log
8.2输入 # grep "password" /var/log/mysqld.log
查找临时密码
8.3修改密码
mysql数据库中有一个validate_password_polic值默认为1,即默认密码且必须含有数字,小写或大写字母,特殊字符。
如果改为简单密码,设置密码字符限制和长度限制
validate_password_policy=0
validate_password_length=1;
登录mysql # mysql -uroot -p
输入临时密码
修改密码字符限制mysql> set global validate_password_policy=0;
修改密码长度限制mysql> set global validate_password_length=1;
修改密码mysql> set password for root@localhost = password('123456');
9. 修改mysql字符编码
查看字符编码mysql> show variables like 'character_set_%';
修改 my.cnf # vi /etc/my.cnf
在[mysqld]下添加 character_set_server = utf8
重启mysql查看编码 # service mysql restart
进入mysql客户端查看编码 # show variables like 'character_set_%';
出现以上所示编码,说明编码修改成功,数据的编码为UTF-8
10.设置mysql可以远程连接
mysql> mysql> set global validate_password_policy=0;
mysql> mysql> set global validate_password_length=1;
mysql> grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
mysql> flush privileges;
11.如果远程连接失败,可能是防火墙端口没打开,打开3306端口
# firewall-cmd --zone=public --add-port=3306/tcp --permanent
# firewall-cmd --reload