https://blog.csdn.net/HECTOR_1368391900/article/details/90732097
https://my.oschina.net/u/3251146/blog/2885657
序言:
如果是首次安裝mysql數據,可以查看日志文件,能找到隨機的密碼,日志文件在配置文件(/etc/my.cnf)
less /var/log/mysqld.log
如果忘記root密碼,重復下面的步驟 能夠重置root密碼
1. 修改Mysql配置文件
vim /etc/my.cnf
添加如下內容:
default-authentication-plugin=mysql_native_password
symbolic-links=0
skip-grant-tables
2.重啟mysql服務
systemctl restart mysqld
3.無密碼登錄
mysql -u root -p
按 enter鍵 進入
4.修改密碼
use mysql;
select user,host,authentication_string from user;
### 密碼設置為空
update user set authentication_string='' where user='root';flush privileges;
quit;
5.退出,重新登錄 進行修改密碼
去掉 步驟1 配置的內容 跳過密碼登錄進去的
#default-authentication-plugin=mysql_native_password
#symbolic-links=0
#skip-grant-tables
重復步驟2 步驟3
6.修改root密碼
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'RootPwd@123456';
### 密碼必須包含兩個大寫字母 、特殊符號、 字母、 數字
7.開放遠程登錄
update user set host ='%' where user='root';
### 同時也要檢查 雲服務器的安全組是否開啟 mysql(3306) 端口號
### 也要檢查 防火牆 開啟對外 mysql(3306) 端口號