如何在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