如何在Ubuntu 20.04上安裝MySQL 8.0

MySQL是一種開源數據庫服務器,通常在三層應用程序中用於存儲和檢索記錄和信息。 它由Oracle Corporation開發。

在MySQL的分支MariaDB出現之前,MySQL是Linux操作系統的主要數據庫服務器。

在這裡,我們將看到如何在Ubuntu 20.04上安裝MySQL 8.0。

在Ubuntu 20.04上安裝MySQL 8.0

MySQL現在在Ubuntu存儲庫和MySQL Dev存儲庫中都可用。 Ubuntu和MySQL社區都只為Ubuntu 20.04提供MySQL v8.0。

從Ubuntu存儲庫安裝MySQL 8.0

從Ubuntu存儲庫安裝MySQL服務器8.0是一個簡單的方法。

更新存儲庫索引。

sudo apt update

使用apt命令安裝MySQL數據庫服務器。

sudo apt install -y mysql-server-8.0 mysql-client-8.0

使用mysql_secure_installation命令設置MySQL根密碼和其他安全設置以保護MySQL實例。

sudo mysql_secure_installation
Output:

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  

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

Re-enter new password: xxx  

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  
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.


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

All done!

MySQL 8.0使用基於改進的SHA 256密碼方法的新身份驗證。 由於新的身份驗證機制,使用libmysqlclient構建的舊客戶端可能無法連接到數據庫服務器。

您可以隨時通過在配置/etc/mysql/my.cnf文件中設置以下內容來更改默認身份驗證插件。

[mysqld]
default-authentication-plugin=mysql_native_password

從MySQL Dev安裝MySQL 8.0

在系統上下載MySQL系統信息庫配置包。

wget https://dev.mysql.com/get/mysql-apt-config_0.8.15-1_all.deb

使用dpkg命令安裝存儲庫軟件包。

sudo dpkg -i mysql-apt-config_0.8.15-1_all.deb

軟件包安裝程序將提示您選擇MySQL存儲庫。 由於MySQL社區僅提供MySQL v8.0,因此只需選擇“確定”,然後按Enter。


MySQL 8.0資料庫

使用apt命令更新存儲庫索引。

sudo apt update

使用apt命令安裝MySQL數據庫服務器

sudo apt install -y mysql-server mysql-client

軟件包安裝程序將提示您設置MySQL根密碼。

僅需按Enter鍵即可跳過設置MySQL根密碼的操作。 如果您將密碼留空,則只能從Unix終端(#或sudo)以MySQL root用戶身份登錄。

設置MySQL根密碼
設置MySQL根密碼

重新輸入密碼。

重新輸入MySQL根密碼
重新輸入MySQL根密碼

MySQL 8.0使用基於改進的SHA 256密碼方法的新身份驗證。 如果選擇此選項,則舊客戶端可能無法連接到服務器。

默認身份驗證插件
默認身份驗證插件

您可以隨時通過在配置/etc/mysql/my.cnf文件中設置以下內容來更改默認身份驗證插件。

[mysqld]
default-authentication-plugin=mysql_native_password

使用mysql_secure_installation命令使此MySQL實例更安全。

sudo mysql_secure_installation
Output:

Securing the MySQL server deployment.

Enter password for user root: xxx 

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  

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  
Using existing password for root.

Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : N  

 ... skipping.
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.


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

All done!

使用MySQL Server

登錄到MySQL服務器。

mysql -u root -p

如果您已從Ubuntu存儲庫安裝MySQL 8.0,則sudo前綴可作為MySQL超級用戶登錄而無需輸入密碼。

Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 14
Server version: 8.0.20 MySQL Community Server - GPL

Copyright (c) 2000, 2020, 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>

結論

就這樣。 我希望您已了解如何在Ubuntu 20.04上安裝MySQL 8.0。 如果您不熟悉MySQL數據庫,請使用phpMyAdmin通過Web瀏覽器進行管理。

Sidebar