源码安装见我的另一篇文章:https://www.jianshu.com/p/41ac166ef477
一、安装
1、CentOS 7上把MySQL从默认软件列表中移除了,用MariaDB来代替。所以运行yum install mysql-server会报如下错误:
[root@VM_38_201_centos ~]# yum install mysql-server
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
No package mysql-server available.
Error: Nothing to do
2、解决方法:安装yum源
(可自己选择下载想要的安装版本,本文安装的 版本5.7.21)
[root@VM_centos ~]# wget http://repo.mysql.com/mysql57-community-release-el7.rpm
[root@VM_centos download]# ls
mysql57-community-release-el7.rpm
[root@VM_centos ~]# rpm -ivh mysql57-community-release-el7.rpm
3、完成上面操作,即可继续安装:
yum install mysql-server mysql-devel mysql
安装mysql,一直输入y回车即可,最后出现Complete! 说明安装完成了
4、服务的启动、停止、查看状态:
systemctl status mysqld.service #查看mysql状态
systemctl start mysqld.service #启动mysql服务
systemctl stop mysqld.service #停止mysql服务
二、登录
1、查找初始密码
[root@VM_centos ~]# grep 'password' /var/log/mysqld.log
2018-01-18T07:40:04.075286Z 1 [Note] A temporary password is generated for root@localhost: .>!66%z*_f:N
2、登录(-u:用户 -p密码)
[root@VM_centos ~]# mysql -uroot -p.>!66%z*_f:N
1)首次登录需更改密码后才能继续操作,报错信息:(修改密码即可)
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
2)修改密码命令:set password=password('123456');
可能会报的错误如下:(原因是密码设置的不符合规定的强度)
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
解决方法,执行以下两条命令即可使用123456做密码了:
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=4;