1. 首次安装使用mysql时,会自动给生成登录密码,可以通过以下命令查看:可以看到密码为 SKL&KG0MhBK=
[xiaokang@localhost tmp]$ cat /var/log/mysqld.log | grep password
2019-06-17T02:12:05.507964Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: SKL&KG0MhBK=
[xiaokang@localhost ~]$ mysql -u root -p SKL&KG0MhBK=
ERRO R 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
报错原因是密码有特殊字符,输入时密码不能和用户名一块输入
可以通过以下方式登录,回车后输入密码即可登录
[xiaokang@localhost ~]$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 21
Server version: 8.0.16 MySQL Community Server - GPL
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
2.设置mysql密码
mysql> set global validate_password_policy=0;
ERROR 1193 (HY000): Unknown system variable 'validate_password_policy'
mysql> set global validate_password_length=1;
ERROR 1193 (HY000): Unknown system variable 'validate_password_length'
这是因为mysql8.0后变量validate_password_policy和validate_password_length已经不存在了
mysql8.0设置策略和长度设置
mysql> set global validate_password.policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password.length=1;
Query OK, 0 rows affected (0.00 sec)
mysql>
设置mysql密码
mysql> SET PASSWORD = PASSWORD('123456');
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 'PASSWORD('123456')' at line 1
报错原因是8.0的设置密码格式变了
8.0mysql密码设置
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.11 sec)
----------------------------------------------------------------------------------------------------------------
以上错误都是因为5.7和8.0版本的操作命令的差异,5.7操作了解就行,要跟着最新数据库版本走
----------------------------------------------------------------------------------------------------------------