阿里雲服務器,centos7,
rpm包安裝MySQL,初始化了個奇葩密碼
登陸不上,
- 修改配置文件/etc/my.cnf,在【mysqld】下面添加一行代碼:skip-grant-tables
- service mysqld restart
- mysql -uroot -p //此時直接回車,既可以進入數據庫。
- 進數據庫后,use mysql //選擇mysql這個庫,因為mysql的root密碼存放在這個數據庫里。
- show tables //查看下mysql庫里有哪些表,我們需要操作的用戶名密碼都在user表里。
- desc user //查看下user表有哪些字段。
- update user set password=password('123456') where user="root"; //用戶選root,可以隨便更改成任意密碼,我這里設置的123456,password()是mysql密碼加密的一個函數。有些數據要執行update user set authentication_string=password('coship') where user="root";才行
- 發現行不通,
- 改用ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
- 報錯:The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
- flush privileges;
- 再次:ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
- ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
- 執行:SHOW VARIABLES LIKE 'validate_password%';
- set global validate_password.policy=0;set global validate_password.length=6;
- 然后再次執行:ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
- Query OK, 0 rows affected (0.03 sec)
- over