MYSQL設定Root帳號密碼與初始權限(Ubuntu 20.04)

Ubuntu 安裝完Mysql的時候預設是沒有root密碼以及相關設定的

這時候就需要先用mysql_secure_installation這個指令來對本機的MySQL進行初始化設定

輸入指令

root@zabbix-server:/home/albertyu# mysql_secure_installation

是否為Root用戶設定密碼並且選擇難度 基本上都是輸入Y

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

選擇密碼難度,這邊基本上都建議是最高強度,輸入2

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: 2

輸入密碼

Please set the password for root here.

New password: 

Re-enter new password: 

系統判斷戲碼強度並且確認是否使用該密碼最強為100,如果強度到80分以上就輸入Y

Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y

預設安裝好了之後會有匿名用戶是否刪除,建議刪除所以輸入Y

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? (Press y|Y for Yes, any other key for No) : Y
Success.

是否禁止遠端登入,如果禁止就只能本機登入,無特殊用途建議輸入Y,如果有外部連入需求任意鍵跳過

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? (Press y|Y for Yes, any other key for No) : 

 ... skipping.

是否刪除測試資料庫,建議輸入Y把多餘不需要的都刪除

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? (Press y|Y for Yes, any other key for No) : Y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

設定最後一個步驟重新載入權限表,輸入Y 重新載入

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
Success.

All done! 

設定完成!