如何在Debian 10(Buster)Linux上安装MySQL

时间:2019-05-19 01:26:21  来源:igfitidea点击:

Debian Buster是Debian操作系统的最新版本。也被称为Debian10。较新的Debian版本在其存储库中默认使用MariaDB。现在,本教程将在Debian10(Buster)Linux系统上安装MySQL8或MySQL5.7。

步骤1–准备工作

使用shell访问登录到Debian10系统。对于远程系统,使用SSH连接。Windows用户可以使用Putty或其他替代应用程序进行SSH连接。

ssh Hyman@theitroad

运行以下命令将当前包升级到最新版本。

sudo apt update 
sudo apt upgrade

步骤2–配置MySQL PPA

MySQL团队为Debian Linux提供官方MySQL PPA。我们可以在Debian系统上下载并安装该软件包,该软件包将向系统添加PPA文件。运行下面的命令以启用PPA。

wget http://repo.mysql.com/mysql-apt-config_0.8.13-1_all.deb
sudo dpkg -i mysql-apt-config_0.8.13-1_all.deb

在安装MySQL apt config包时,会提示选择MySQL版本进行安装。选择MySQL 8.0或5.7选项以在系统上安装。

在本教程中,我们选择了MySQL 5.7来安装在我的Debian系统上。选择特定版本后,需要更改配置时,请使用以下命令。

sudo dpkg-reconfigure mysql-apt-config

选择我们选择的版本并保存。

第3步-在Debian 10上安装MySQL

系统已准备好进行MySQL安装。运行以下命令在Debian机器上安装MySQL。

sudo apt update 
sudo apt install mysql-server

安装过程将提示将root密码设置为默认值。输入一个安全密码和相同的确认密码窗口。这将是登录MySQL服务器所需的MySQL root用户密码。

下一个窗口将要求重新输入相同的密码。

MySQL 8提供了一个扩展的密码安全选项。这是可选的,但我们建议使用此选项。

步骤4–MySQL安全设置

在系统上执行以下命令以对数据库服务器进行安全更改。这会引发一些问题。

如果未启动,请首先启动MysQL服务:

sudo systemctl restart mysql.service

然后运行以下命令:

sudo mysql_secure_installation

按照屏幕上的说明

Securing the MySQL server deployment.

Enter password for user root:

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

[...]

选择密码验证策略为“中”或“强”。之后,进程将要求更改密码。我们可以选择更复杂的密码。按照其他选项完成向导。

第5步-连接MySQL

MySQL服务器已经安装在系统上。现在使用命令行连接到MySQL数据库。

 **mysql -u root -p**  

Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.17 MySQL Community Server - GPL

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