原作者:Rahul;

原文:https://tecadmin.net/install-mysql-on-debian-10-buster/

翻译:非科学の河童


目前,Debian 10 Buster是Debian GNU/Linux操作系统的最新版本。最新放出的版本使用MariaDB作为主要的数据库服务器。现在,本教程将帮助你在Debian 10 GNU/Linux操作系统上安装MySQL 8或MySQL 5.7。

准备工作

首先,你必须拥有sudo管理员权限来执行之后的命令。登录Debian 10。访问远程的服务器可以通过ssh。Windows用户可以通过PUTTY或者其他的SSH客户端登录。(Windows自带SSH,所以下面的命令应该同样适用)

1
$ ssh 你的用户名@debian10

运行以下的命令更新已安装的软件包:

1
2
$ sudo apt update 
$ sudo apt upgrade

配置MySQL的PPA

MySQL团队提供官方的debian PPA源。你只需要下载安装官方的软件包在你的Debian上。

1
2
$ wget http://repo.mysql.com/mysql-apt-config_0.8.13-1_all.deb
$ sudo apt install ./mysql-apt-config_0.8.13-1_all.deb
P.S. 原文的方式是dpkg -i,但在WSL debian buster下尝试后失败了。(后来也没有在WSL上安装好)

在安装过程中会提示选择版本。选择MySQL 8.0或5.7以继续安装。

MySQL Debian

在本教程中将安装MySQL 5.7。如果你要选择其他版本,你可以通过以下命令更改配置。

1
$ sudo dpkg-reconfigure mysql-apt-config

然后选择一个版本,保存。

安装MySQL

你的系统已经准备完毕,通过以下命令安装MySQL。

1
2
$ sudo apt update 
$ sudo apt install mysql-server

安装进程会提示你设置服务的root密码。务必选择一个安全的密码,并在确认窗口中输入相同的密码。

MySQL设置root密码

在下一个窗口中会让你再输入一遍原始的密码。

MySQL密码安全配置

MySQL 8支持额外的密码保护选项。这是可选的但我们仍推荐设置该项。

MySQL安全配置

在系统中运行以下命令以进行数据库服务器的安全配置。这将提示几个问题,全选最安全。

1
$ sudo systemctl restart mysql.service

然后运行以下命令:

1
$ sudo mysql_secure_installation

根据提示:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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

[...]

选择一个达到中(MEDIUM)、高安全度(STRONG)的密码校验规则。在此之后,安全配置向导会要求更改密码,你可以选择一个更复杂的密码。之后便配置其他选项以结束安全配置。

连接MySQL服务器

到这里,MySQL服务已经安装完成了。现在,通过以下的命令访问MySQL数据库。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ 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>