获取源
sudo rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
安装mysql 8.0
sudo yum --enablerepo=mysql80-community install mysql-community-server
- 启动服务
service mysqld start - 查看状态
service mysqld status
- 查看临时密码
grep "A temporary password" /var/log/mysqld.log - 登陆mysql后输入临时密码即可
mysql -u root -p
-
修改密码
alter user 'root'@'localhost' identified by 'zxcv1234'- 这个@和两侧的单引号直接不要有空格,否则会报错语法有误
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘‘localhost’ identified by ‘zxcv1234’’ at line 1
- 这个单引号也要注意,不要打成 Esc键下面的那个小点,否则报错语法有误
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ’
localhostidentified byzxcv1234’ at line 1
- 疯狂提示我不符合规则,也执行不了其他的命令
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
- 查询资料得知默认的政策要求是 为 1
- 这个@和两侧的单引号直接不要有空格,否则会报错语法有误
| 策略 | 规则 |
|---|---|
| 0 or LOW | Length |
| 1 or MEDIUM | Length; numeric, lowercase/uppercase, and special characters |
| 2 or STRONG | Length; numeric, lowercase/uppercase, and special characters; dictionary file |
- 0 or LOW Length:密码任意,长度8位及以上
- 1 or MEDIUM Length; numeric, lowercase/uppercase, and special characters:表示的是数字、大小写字母、特殊字符,长度任意
- 2 or STRONG Length; numeric, lowercase/uppercase, and special characters; dictionary file:限制与 1 差不多,但是密码会通过字典检查,通俗的说太简单的密码无法通过
修改策略(这个为可选)
- 查询策略
show variables like 'validate_password.%'; - 修改策略
set global validate_password.policy=0,令密码任意,长度大于等于8