1. 服务器上下载rmp文件
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
2. 开始安装MySQL
2.1 rpm -ivh mysql80-community-release-el7-3.noarch.rpm
# 命令完毕后,在 /etc/yum.repos.d/ 目录下新增 mysql-community.repo 、mysql-community-source.repo 两个yum 源文件
2.2 安装MySQL
yum install mysql-server
2.3 检查MySQL是否安装成功
rpm -qa | grep mysql
3 启动MySQL
①systemctl start mysqld.service #启动 mysql
②systemctl restart mysqld.service #重启 mysql
③systemctl stop mysqld.service #停止 mysql
④systemctl enable mysqld.service #设置 mysql 开机启动
4 设置密码
4.1 使用临时密码登录
mysql启动后,会生成一个随机的密码,在/var/log/mysqld.log日志文件中,使用如下命令可以找到临时密码
//查找临时密码
grep 'temporary password' /var/log/mysqld.log
//输出为
[Note] [MY-010454] [Server] A temporary password is generated for root@localhost: myKape2RrC&t
可以看到临时密码是:myKape2RrC&t
- 登陆mysql
mysql -uroot -p
输入密码 myKape2RrC&t
4.2 修改密码
// 适用于sql的老版本如mysql5.0
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=4
// 新版本如mysql8.0就不支持了
// 为啥呢,进入mysql命令后,输入下面命令就清清楚楚了!
mysql> SHOW VARIABLES LIKE 'validate_password%';
// 结果如下
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password.check_user_name | ON |
| validate_password.dictionary_file | |
| validate_password.length | 8 |
| validate_password.mixed_case_count | 1 |
| validate_password.number_count | 1 |
| validate_password.policy | MEDIUM |
| validate_password.special_char_count | 1 |
+--------------------------------------+--------+
7 rows in set (0.01 sec)
4.2.1 set global validate_password.policy=0;
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------+-------+
| validate_password.check_user_name | ON |
| validate_password.dictionary_file | |
| validate_password.length | 8 |
| validate_password.mixed_case_count | 1 |
| validate_password.number_count | 1 |
| validate_password.policy | LOW |
| validate_password.special_char_count | 1 |
+--------------------------------------+-------+
密码长度为8
4.2.2 设置密码为12345678
ALTER USER 'root'@'localhost' IDENTIFIED BY '12345678';
4.2.3 使用 root / 12345678 登录MySQL