mysql 5.7 默認密碼及密碼修改

 

1. Mysql 5.7 在自動初始化數據庫的時候,會生成root用戶的默認密碼。mysql

經過 grep "temporary password" /var/log/mysqld.log 命令,返回結果最後冒號後面的字符串就是root的默認密碼。sql

 

使用此密碼登陸後,Mysql 會要求第一件作的事就是改root密碼,並且是要求強密碼。能夠經過set password=password('密碼')來更改。數據庫

2. 沒法找到密碼,忘記設置的是啥了centos

在/etc/my.cnf 中添加 skip-grant-tables 參數。此參數的做用是登陸Mysql 數據庫不進行用戶密碼驗證。ide

修改後, 重啓服務  systemctl restart mysqld.
[root@VM_0_15_centos ~]# service mysqld restart
Stopping mysqld: [ OK ] Starting mysqld: [ OK ] [root@VM_0_15_centos ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.26 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> update mysql.user set authentication_string=password('123456pswd') where user='root' and Host = 'localhost'; Query OK, 1 row affected, 1 warning (0.00 sec) Rows matched: 1  Changed: 1  Warnings: 1 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> quit Bye
# 將/etc/my.cnf 中 skip-grant-tables 註釋,重啓服務
[root@VM_0_15_centos ~]# mysql -p
Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.26 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>

 

 ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.測試

設置一個簡單的測試密碼的話,如123456,會提示這個錯誤.ui

mysql>   alter user 'root'@'localhost' identified by 'password';this

或者  mysql>   set password=password("password");spa

mysql> show databases; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. mysql> alter user 'root'@'localhost' identified by '123456pswd'; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> show databases; +--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| ops |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec) mysql> quit Bye

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

相關文章
相關標籤/搜索