參考文章:
因為我需要連接數據庫工具,需要密碼,所以下面介紹如何設置、修改密碼實現Navicat Premium連接Mysql數據庫
建議生產環境中mysql安裝這完成后一定要運行一次mysql_secure_installation,在這里可以第一次設置密碼,后續修改密碼規則時可以多次修改密碼,見下面:二、修改密碼規則以及多次修改密碼(但是,如果設置密碼太簡單低級會遇到密碼策略問題,參考文章)
一、安全配置設置初始密碼
啟動mysql
mysql.server start
設置密碼:
mysql_secure_installation
運行mysql_secure_installation會執行幾個設置:
a)為root用戶設置密碼
b)刪除匿名賬號
c)取消root用戶遠程登錄
d)刪除test庫和對test庫的訪問權限
e)刷新授權表使修改生效
代碼如下:
Securing the MySQL server deployment. Connecting to MySQL using a blank password. VALIDATE PASSWORD COMPONENT can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD component? Press y|Y for Yes, any other key for No: y ==》輸入y There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0 ==》選擇高中低密碼,我選的0低級 Please set the password for root here. New password: ==》輸入新密碼 Re-enter new password: ==》再次輸入新密碼 Estimated strength of the password: 50 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y ==》安全只有50,輸入y Password updated successfully! Reloading privilege tables.. … Success! By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n]<– 是否刪除匿名用戶,生產環境建議刪除,所以直接回車 … Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n]<–是否禁止root遠程登錄,根據自己的需求選擇Y/n並回車,建議禁止 … Success! By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n]<– 是否刪除test數據庫,直接回車 - Dropping test database… … Success! - Removing privileges on test database… … Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n]<– 是否重新加載權限表,直接回車 … Success! Cleaning up… All done! If you've completed all of the above steps, your MySQL installation should now be secure. Thanks for using MySQL! [root@server1 ~]#
初始密碼設置成功,驗證一下,登陸mysql:
#登陸mysql mysql -u root -p
輸入密碼:xxxx
能進入就成功了!!!
二、修改密碼規則以及可以多次修改密碼
再返回到Navicat Premium中,


2059 - Authentication plugin 'caching_sha2_password' cannot be loaded: dlopen(../Frameworks/caching_sha2_password.so, 2): image not found
解決上面問題參考:《Navicat連接數據庫MySQL報錯2059》
是密碼規則問題,解決問題如下:
#登陸mysql mysql -u root -p #輸入密碼 Enter password: xxx #修改加密規則 ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER; #更新一下用戶的密碼 ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'; #刷新權限 FLUSH PRIVILEGES;
效果圖:

但是,重新連接Navicat Premium時,還是報錯

1045 - Access denied for user 'root'@'localhost' (using password: YES)
是因為,我上一步在更新密碼中又把密碼設置為“password”了,所以重新輸入密碼,再連接

