MySQL is a free and opensource database server which is very popular in the opensource community. MySQL is used by a lot of applications and companies like Facebook, Google, etc. In this tutorial, we will learn how to install MySQL into deb or apt-based distributions like Ubuntu, Debian, Mint, and Kali. This guide can be used for other deb
or apt
based distributions too.
MySQL是一个免费的开源数据库服务器,在开源社区中非常流行。 许多应用程序和公司(例如Facebook,Google等)都使用MySQL。在本教程中,我们将学习如何将MySQL安装到基于Deb或apt的发行版中,如Ubuntu,Debian,Mint和Kali。 本指南也可用于其他基于deb
或apt
的发行版。
![](https://i-blog.csdnimg.cn/blog_migrate/286355b5b6e5f5e940713163c537b330.png)
更新存储库信息 (Update Repository Information)
It is not a requirement but a best practice to update repository information which will provide us the newest information about MySQL.
这不是必需的,而是更新存储库信息的最佳实践,它将为我们提供有关MySQL的最新信息。
$ sudo apt update
![Update Repository Information](https://i-blog.csdnimg.cn/blog_migrate/e2dd7e96cd7079e5a7ec255dbe33484c.png)
从Apt存储库安装MySQL Server(Install MySQL Server From Apt Repository)
MySQL Server application is named as mysql-server
as package name. We can use apt
or apt-get
in order to install mysql-server
package like below. We can also use -y
option in order to automatically accept conformation.
MySQL Server应用程序名为mysql-server
作为程序包名称。 我们可以使用apt
或apt-get
来安装mysql-server
软件包,如下所示。 我们也可以使用-y
选项来自动接受构象。
$ sudo apt install mysql-server
![Install MySQL Server From Apt Repository](https://i-blog.csdnimg.cn/blog_migrate/5273a200c698e190a9ad0234b178bf36.png)
下载MySQL服务器二进制文件 (Download MySQL Server Binary)
Another way to install MySQL is from a binary installation file. We can download MySQL binary from official download site mysql.com. But keep in mind that different versions of MySQL Server are provided with different licenses and costs. We will use community version for Ubuntu which can be listed from the following link.
另一种安装MySQL的方法是从二进制安装文件。 我们可以从官方下载站点mysql.com下载MySQL二进制文件。 但是请记住,不同版本MySQL Server具有不同的许可证和成本。 我们将使用Ubuntu的社区版本,可以从以下链接中列出。
https://dev.mysql.com/downloads/mysql/
https://dev.mysql.com/downloads/mysql/
and we will download the deb
package with wget
.
我们将使用wget
下载deb
软件包。
$ wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-server_8.0.11-1ubuntu18.04_amd64.deb-bundle.tar
![Download MySQL Server Binary](https://i-blog.csdnimg.cn/blog_migrate/6590fe6cbc99d94e275e93dc5a66fd83.png)
安装MySQL Binary Deb软件包(Install MySQL Binary Deb Package)
After the download is completed we will first extract the tar
archive like below.
下载完成后,我们将首先提取tar
存档,如下所示。
$ tar xvf mysql-server_8.0.11-1ubuntu18.04_amd64.deb-bundle.tar
![Install MySQL Binary Deb Package](https://i-blog.csdnimg.cn/blog_migrate/12212da09ff5be3d43a59615fcbe321a.png)
and we will install the mysql-community-server_8.0.11-1ubuntu18.04_amd64.deb
package with dpkg
like below.
然后我们将使用dpkg
安装mysql-community-server_8.0.11-1ubuntu18.04_amd64.deb
软件包,如下所示。
$ sudo dpkg -i mysql-community-server_8.0.11-1ubuntu18.04_amd64.deb
安全MySQL服务器安装 (Secure MySQL Server Installation)
Security is an important part of today’s IT systems. We can make MySQL more secure by using mysql_secure_installation
hardening script. This will run some commands which will change MySQL configuration and harden it. This script will start by asking root
password and then ask some questions about security.
安全性是当今IT系统的重要组成部分。 我们可以使用mysql_secure_installation
强化脚本来使MySQL更安全。 这将运行一些命令,这些命令将更改MySQL配置并对其进行强化。 该脚本将首先询问root
密码,然后询问有关安全性的一些问题。
$ sudo mysql_secure_installation
![Secure MySQL Installation](https://i-blog.csdnimg.cn/blog_migrate/58b3d4b3d313a105382fdf2b2577f96f.png)
显示MySQL服务或守护程序状态(Show MySQL Service or Daemon Status)
After the installation is completed and secured we can list the status of the MySQL server. We will use systemctl
command with status
option to list whether the MySQL daemon is working or not.
在完成安装并确保其安全之后,我们可以列出MySQL服务器的状态。 我们将使用带有status
选项的systemctl
命令来列出MySQL守护程序是否正在运行。
$ systemctl status mysql
![Show MySQL Service or Daemon Status](https://i-blog.csdnimg.cn/blog_migrate/81b5e7cd17192967dcaa38bbe87b27a9.png)
As we can see the daemon is running properly.
如我们所见,守护程序运行正常。
启动MySQL服务/守护程序/服务器(Start MySQL Service/Daemon/Server)
If the MySQL service is not started or stopped with a reason we can start MySQL service with start
option like below.
如果由于某种原因未启动或停止MySQL服务,我们可以使用如下所示的start
选项来启动MySQL服务。
$ systemctl start mysql
停止MySQL服务/守护程序/服务器 (Stop MySQL Service/Daemon/Server)
If we need to stop the MySQL daemon we can use stop
option. This can be useful to apply a new configuration by stopping and starting the service.
如果我们需要停止MySQL守护程序,则可以使用stop
选项。 这对于通过停止和启动服务来应用新配置很有用。
$ systemctl stop mysql
通过登录测试MySQL服务器 (Test MySQL Server By Logging In)
We can test the MySQL server by connecting to the service console with mysql
command. We also need to provide the username and the password like below.
我们可以通过使用mysql
命令连接到服务控制台来测试MySQL服务器。 我们还需要提供用户名和密码,如下所示。
$ mysql -u root -p
![Test MySQL Server](https://i-blog.csdnimg.cn/blog_migrate/881df6ffde59a1bdc3dc0ff718666e5e.png)
翻译自: https://www.poftut.com/how-to-install-mysql-on-ubuntu-debian-mint-kali/