博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何在CentOS 8上安装MySQL
阅读量:2510 次
发布时间:2019-05-11

本文共 9009 字,大约阅读时间需要 30 分钟。

介绍 (Introduction)

is an open-source database management system, commonly installed as part of the popular (Linux, Nginx, MySQL/MariaDB, PHP/Python/Perl) stack. It implements the and (SQL) to manage and query data.

是一个开源数据库管理系统,通常作为流行的 (Linux,Nginx,MySQL / MariaDB,PHP / Python / Perl)堆栈的一部分安装。 它实现了和 (SQL)来管理和查询数据。

This tutorial explains how to install MySQL version 8 on a CentOS 8 server.

本教程说明了如何在CentOS 8服务器上安装MySQL版本8。

先决条件 (Prerequisites)

To complete this tutorial, you will need a server running CentOS 8. This server should have a non-root user with administrative privileges and a firewall configured with firewalld. To set this up, see our .

要完成本教程,您将需要一台运行CentOS 8的服务器。该服务器应具有具有管理特权的非root用户,以及一个配置有firewalld 。 要进行设置,请参阅我们 。

第1步-安装MySQL (Step 1 — Installing MySQL)

On CentOS 8, MySQL version 8 is available from the default repositories.

在CentOS 8上,默认存储库中提供了MySQL版本8。

Run the following command to install the mysql-server package and a number of its dependencies:

运行以下命令以安装mysql-server软件包及其依赖项:

  • sudo dnf install mysql-server

    sudo dnf安装mysql服务器

When prompted, press y and then ENTER to confirm that you want to proceed:

出现提示时,按y ,然后按ENTER以确认您要继续:

Output   
. . .Install 49 PackagesTotal download size: 46 MInstalled size: 252 MIs this ok [y/N]: y

With that, MySQL is installed on your server but it isn’t yet operational. The package you just installed configures MySQL to run as a systemd service named mysqld.service. In order to use MySQL, you will need to start it with the systemctl command:

这样,MySQL已安装在您的服务器上,但尚未运行。 您刚安装的软件包将MySQL配置为作为名为mysqld.servicesystemd服务运行。 为了使用MySQL,您需要使用systemctl命令启动它:

  • sudo systemctl start mysqld.service

    sudo systemctl启动mysqld.service

To check that the service is running correctly, run the following command. Note that for many systemctl commands — including start and, as shown here, status — you don’t need to include .service after the service name:

要检查服务是否正常运行,请运行以下命令。 请注意,对于许多systemctl命令-包括startstatus (如此处所示)-您无需在服务名称后包含.service

  • sudo systemctl status mysqld

    sudo systemctl状态mysqld

If MySQL was successfully started, the output will show that the MySQL service is active:

如果成功启动了MySQL,则输出将显示MySQL服务处于活动状态:

Output   
● mysqld.service - MySQL 8.0 database server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Thu 2020-03-12 14:07:41 UTC; 1min 7s ago Main PID: 15723 (mysqld) Status: "Server is operational" Tasks: 38 (limit: 5056) Memory: 474.2M CGroup: /system.slice/mysqld.service └─15723 /usr/libexec/mysqld --basedir=/usrMar 12 14:07:32 cent-mysql-3 systemd[1]: Starting MySQL 8.0 database server...Mar 12 14:07:32 cent-mysql-3 mysql-prepare-db-dir[15639]: Initializing MySQL databaseMar 12 14:07:41 cent-mysql-3 systemd[1]: Started MySQL 8.0 database server.

Next, set MySQL to start whenever the server boots up with the following command:

接下来,将MySQL设置为在服务器启动时使用以下命令启动:

  • sudo systemctl enable mysqld

    sudo systemctl启用mysqld

Note: If you ever want to change this behavior and disable MySQL from starting up at boot, you can do so by running:

注意:如果您想更改此行为并禁止MySQL在启动时启动,则可以通过运行以下命令来进行:

  • sudo systemctl disable mysqld

    sudo systemctl禁用mysqld

MySQL is now installed, running, and enabled on your server. Next, we’ll go over how to harden your database’s security using a shell script that came preinstalled with your MySQL instance.

现在已在服务器上安装,运行并启用了MySQL。 接下来,我们将讨论如何使用MySQL实例预装的Shell脚本来增强数据库的安全性。

第2步-保护MySQL安全 (Step 2 — Securing MySQL)

MySQL includes a security script that allows you to change some default configuration options in order to improve MySQL’s security.

MySQL包含一个安全脚本,该脚本允许您更改一些默认配置选项以提高MySQL的安全性。

To use the security script, run the following command:

要使用安全脚本,请运行以下命令:

  • sudo mysql_secure_installation

    须藤mysql_secure_installation

This will take you through a series of prompts asking if you want to make certain changes to your MySQL installation’s security options. The first prompt will ask whether you’d like to set up the Validate Password Plugin, which you can use to test the strength of your MySQL password.

这将引导您完成一系列提示,询问您是否要对MySQL安装的安全性选项进行某些更改。 第一个提示将询问您是否要设置验证密码插件,该插件可用于测试MySQL密码的强度。

If you elect to set up the Validate Password Plugin, the script will ask you to choose a password validation level. The strongest level — which you select by entering 2 — will require your password to be at least eight characters long and include a mix of uppercase, lowercase, numeric, and special characters:

如果选择设置“验证密码插件”,则脚本将要求您选择密码验证级别。 输入2选择的最高级级别将要求密码长度至少为八个字符,并包括大写,小写,数字和特殊字符的组合:

Output   
Securing the MySQL server deployment.Connecting to MySQL using a blank password.VALIDATE PASSWORD COMPONENT can be used to test passwordsand improve security. It checks the strength of passwordand allows the users to set only those passwords which aresecure enough. Would you like to setup VALIDATE PASSWORD component?Press y|Y for Yes, any other key for No: YThere are three levels of password validation policy:LOW Length >= 8MEDIUM Length >= 8, numeric, mixed case, and special charactersSTRONG Length >= 8, numeric, mixed case, special characters and dictionary filePlease enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2

Regardless of whether you choose to set up the Validate Password Plugin, the next prompt will be to set a password for the MySQL root user. Enter and then confirm a secure password of your choice:

无论您是否选择设置“验证密码插件”,下一个提示都是为MySQL 用户设置密码。 输入,然后确认您选择的安全密码:

Output   
Please set the password for root here.New password: Re-enter new password:

If you used the Validate Password Plugin, you’ll receive feedback on the strength of your new password. Then the script will ask if you want to continue with the password you just entered or if you want to enter a new one. Assuming you’re satisfied with the strength of the password you just entered, enter Y to continue the script:

如果您使用了验证密码插件,您将收到有关新密码强度的反馈。 然后,脚本将询问您是否要继续使用刚输入的密码,还是要输入一个新密码。 假设您对刚输入的密码的强度感到满意,请输入Y继续执行脚本:

Output   
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

Following that, you can press Y and then ENTER to accept the defaults for all the subsequent questions. This will remove some anonymous users and the test database, disable remote root logins, and load these new rules so that MySQL immediately respects the changes you have made.

之后,您可以按Y ,然后按ENTER以接受所有后续问题的默认设置。 这将删除一些匿名用户和测试数据库,禁用远程root登录,并加载这些新规则,以便MySQL立即尊重您所做的更改。

With that, you’ve installed and secured MySQL on your CentOS 8 server. As a final step, we will test that the database is accessible and working as expected.

这样,您就可以在CentOS 8服务器上安装并保护MySQL。 作为最后一步,我们将测试数据库是否可以访问并可以按预期工作。

第3步-测试MySQL (Step 3 — Testing MySQL)

You can verify your installation and get information about it by connecting with the mysqladmin tool, a client that lets you run administrative commands. Use the following command to connect to MySQL as root (-u root), prompt for a password (-p), and return the installation’s version:

您可以通过与mysqladmin工具连接来验证安装并获取有关安装的信息,该工具允许您运行管理命令。 使用以下命令以root用户身份( -u root )连接到MySQL,提示输入密码( -p ),并返回安装版本:

  • mysqladmin -u root -p version

    mysqladmin -u root -p版本

You will see output similar to this:

您将看到类似于以下的输出:

Output
输出量
mysqladmin  Ver 8.0.17 for Linux on x86_64 (Source distribution)Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Server version      8.0.17Protocol version    10Connection      Localhost via UNIX socketUNIX socket     /var/lib/mysql/mysql.sockUptime:         2 hours 52 min 37 secThreads: 2  Questions: 20  Slow queries: 0  Opens: 131  Flush tables: 3  Open tables: 48  Queries per second avg: 0.001

This indicates your installation was successful.

这表明安装成功。

If you’d like to connect to MySQL and begin adding data to it, run the following:

如果您想连接到MySQL并开始向其中添加数据,请运行以下命令:

  • mysql -u root -p

    mysql -u root -p

Like the previous mysqladmin command, this command includes the -u option, which allows you to specify the user you’d like to connect as (root in this case), and the -p option, which tells the command to prompt you for the user password you set in the previous step.

与上一个mysqladmin命令类似,此命令包括-u选项和-p选项,该选项允许您指定要连接的用户(在本例中为root ),- -p选项告诉该命令提示您输入您在上一步中设置的用户密码。

After you enter your root MySQL user’s password, you will see the MySQL prompt:

输入您的root MySQL用户密码后,您将看到My​​SQL提示符:

From there, you can begin using your MySQL installation to create and load databases and start running queries.

从那里,您可以开始使用MySQL安装来创建和加载数据库并开始运行查询。

结论 (Conclusion)

By following this tutorial, you’ve installed and secured MySQL on a CentOS 8 server. From here, you could install Nginx and PHP to have a fully operational on your server.

通过遵循本教程,您已经在CentOS 8服务器上安装并保护了MySQL。 从这里,您可以安装Nginx和PHP以在服务器上具有完全可操作的 。

To learn more about using MySQL, we encourage you to review the .

要了解有关使用MySQL的更多信息,我们建议您阅读 。

翻译自:

转载地址:http://qphgb.baihongyu.com/

你可能感兴趣的文章
win10操作系统安装oracle11g时出现不满足最低配置的操作INS13001
查看>>
中文乱码问题(页面乱码,eclipse乱码,请求响应乱码)
查看>>
extern使用方法总结!(转)
查看>>
HTTP请求过程详解
查看>>
【C#】wpf中的xmlns命名空间为什么是一个网址,代表了什么意思(转载)
查看>>
你不是迷茫,你是自制力不强
查看>>
【转载】setContentView和inflate区别
查看>>
Bootstrap栅格系统
查看>>
自然语言工程师要求
查看>>
Leetcode 452.用最少数量的箭引爆气球
查看>>
【转】Linux设备驱动之Ioctl控制
查看>>
实例说明>
查看>>
日常理财
查看>>
ng-bind-html在ng-repeat中问题的解决办法
查看>>
制定document.getElementByClassName()
查看>>
UVA-315 无向图求割点个数
查看>>
Python学习_4_购物车
查看>>
ubuntu开机自启动
查看>>
【WXS数据类型】Number
查看>>
canvas学习笔记 ---- 1
查看>>