如何在 Ubuntu 20.04 上安装 MySQL

MySQL是最流行的开源关系数据库管理系统。它快速、易于使用、可扩展,是流行和堆栈中不可或缺的一部分。

先决条件

请确保您以具有 sudo权限的用户登录。

在 Ubuntu 上安装 MySQL

在撰写本文时,Ubuntu 存储库中提供的最新版本MySQL 是 MySQL 版本8.0。要安装它,请运行以下命令:

sudo apt update
sudo apt install mysql-server

安装完成后,MySQL 服务将自动启动。要验证 MySQL 服务器是否正在运行,请键入:

sudo systemctl status mysql

输出应显示服务已启用并运行:

● mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2020-04-28 20:59:52 UTC; 10min ago
   Main PID: 8617 (mysqld)
     Status: "Server is operational"
     ...

MySQL

MySQL 安装附带一个名为 的脚本,允许您轻松提高数据库服务器的安全性。mysql_secure_installation

调用脚本而不引发参数:

sudo mysql_secure_installation

您将被要求配置验证密码插件,用于测试 MySQL 用户密码的强度并提高安全性:

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

在下一个提示中,系统将要求您为 MySQL 根用户设置密码:

Please set the password for root here.


New password: 

Re-enter new password: 

如果您设置了验证密码插件,脚本将显示新密码的强度。键入以确认密码:y

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

接下来,系统将要求您删除匿名用户、限制根用户访问本地计算机、删除测试数据库以及重新加载权限表。你应该回答所有问题。y

登录为根

若要从命令行与 MySQL 服务器进行交互,请使用作为 MySQL 服务器包的依赖项安装的 MySQL 客户端实用程序。

在 MySQL 8.0 上,默认情况下,根用户由插件进行身份验证。auth_socket

该插件对从 Unix 套接字文件连接的用户进行身份验证。这意味着您无法通过提供密码来验证为 root。auth_socketlocalhost

 

要以根用户类型登录 MySQL 服务器:

sudo mysql

您将看到 MySQL 外壳,如下所示:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.19-0ubuntu5 (Ubuntu)

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>

如果要使用外部程序(如 phpMyAdmin)以根版本名登录到 MySQL 服务器,您有两种选择。

第一个是将身份验证方法从 更改为 。您可以通过运行以下命令来做到这一点:auth_socketmysql_native_password

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'very_strong_password';
FLUSH PRIVILEGES;

第二个建议的选项是创建一个有权访问所有数据库的新专用管理用户:

GRANT ALL PRIVILEGES ON *.* TO 'administrator'@'localhost' IDENTIFIED BY 'very_strong_password';

我们已经告诉你如何在Ubuntu20.04上安装 MySQL。现在数据库服务器已启动并运行,下一步可能是学习如何管理 MySQL 用户帐户和数据库。

 

原创文章,作者:校长,如若转载,请注明出处:https://www.yundongfang.com/Yun35871.html

(0)
打赏 微信扫一扫不于多少! 微信扫一扫不于多少! 支付宝扫一扫礼轻情意重 支付宝扫一扫礼轻情意重
上一篇 2021年2月4日 下午10:24
下一篇 2021年2月4日

相关推荐