debian 安装mysql5.5,如何在Debian 9上安装MySQL

随着Debian 9 Stretch MySQL的发布,Debian的存储库中不再提供世界上最受欢迎的开源关系数据库管理系统,MariaDB已成为默认的数据库系统。 MariaDB是MySQL的向后兼容二进制替代。

在本教程中,我们将向您展示如何从MySQL Apt Repository在Debian 9计算机上安装和保护MySQL。如果您的应用程序没有任何特定要求,则应坚持使用MariaDB,这是Debian 9中的默认数据库系统。

先决条件

第1步:配置MySQL存储库

要将MySQL APT存储库添加到您的系统,请访问存储库下载页面,并使用以下wget命令下载最新的发行包:wget http://repo.mysql.com/mysql-apt-config_0.8.10-1_all.deb

下载完成后,使用以下命令安装发行包:sudo dpkg -i mysql-apt-config_0.8.10-1_all.deb

系统将显示配置菜单,您可以在其中选择要安装的MySQL版本。

已预先选择MySQL 8.0,如果要安装其他版本的MySQL,请选择MySQL Server & Cluster (Currently selected: mysql-8.0),然后选择首选的MySQL版本

我们将安装MySQL 8.0版。选择最后一个选项OK,然后按Enter(如上图所示)以保存配置。

在撰写本文时,MySQL的最新版本是8.0版。如果不确定要选择哪个版本,请查阅要在服务器上部署的应用程序的文档。

步骤2:安装MySQL

在您的Debian 9服务器上安装MySQL之前,首先使用以下信息更新软件包列表:sudo apt update

更新软件包列表后,运行以下命令在您的Debian服务器上安装MySQL:sudo apt install mysql-server

安装程序将要求您设置MySQL root密码。现在不要设置密码(将其保留为空白),我们将在下一部分中进行设置。

接下来,您将看到一条消息,通知您有关新的MySQL 8身份验证的信息。在选择默认的MySQL 8身份验证插件之前,请确保您的应用程序支持它。

第3步:验证MySQL安装

安装完成后,MySQL服务将自动启动。

我们可以通过输入以下内容来检查MySQL服务状态:sudo systemctl status mysql● mysql.service - MySQL Community Server

Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset:

Active: active (running) since Thu 2018-08-02 17:22:18 UTC; 18s ago

Docs: man:mysqld(8)

http://dev.mysql.com/doc/refman/en/using-systemd.html

Process: 14797 ExecStartPre=/usr/share/mysql-8.0/mysql-systemd-start pre (co

Main PID: 14832 (mysqld)

Status: "SERVER_OPERATING"

Tasks: 37 (limit: 4915)

CGroup: /system.slice/mysql.service

└─14832 /usr/sbin/mysqld

步骤4:保护MySQL

运行mysql_secure_installation命令来设置root密码并提高MySQL安装的安全性:sudo mysql_secure_installationSecuring 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:

将要求您配置VALIDATE PASSWORD PLUGIN,该工具用于测试MySQL用户密码的强度。密码验证策略分为三个级别:低,中和强。如果您不想设置验证密码插件,请按ENTER。Please set the password for root here.

New password:

Re-enter new password:

在下一个提示符下,将要求您为MySQL根用户设置密码。By default, a MySQL installation has an anonymous user,

allowing anyone to log into MySQL without having to have

a user account created for them. This is intended only for

testing, and to make the installation go a bit smoother.

You should remove them before moving into a production

environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y

Success.

Normally, root should only be allowed to connect from

'localhost'. This ensures that someone cannot guess at

the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y

Success.

By default, MySQL comes with a database named 'test' that

anyone can access. This is also intended only for testing,

and should be removed before moving into a production

environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y

- Dropping test database...

Success.

- Removing privileges on test database...

Success.

Reloading the privilege tables will ensure that all changes

made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y

Success.

All done!

一旦您设置了root密码,脚本还将要求您删除匿名用户,限制root用户对本地计算机的访问并删除测试数据库。您应该对所有问题回答“是”。

第5步:从命令行连接到MySQL

要通过终端与MySQL进行交互,我们将使用作为MySQL服务器软件包依赖项安装的MySQL客户端。

以root用户身份登录MySQL服务器:mysql -u root -p

运行mysql_secure_installation脚本时,系统会提示您输入先前设置的root密码。

输入密码后,将显示MySQL外壳,如下所示:Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 10

Server version: 8.0.12 MySQL Community Server - GPL

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

创建数据库

一旦连接到MySQL Shell,就可以通过键入以下命令来创建新数据库:CREATE DATABASE new_database;Query OK, 1 row affected (0.00 sec)

创建表格

现在我们已经创建了数据库,我们可以创建一个表来存储一些数据。

在运行用于创建表的SQL语句之前,我们需要连接到数据库:use new_database;

在此示例中,我们将创建一个名为contacts的简单表,其中包含三个字段id,name和email:CREATE TABLE contacts (

id INT PRIMARY KEY,

name VARCHAR(30),

email VARCHAR(30)

);Query OK, 1 row affected (0.00 sec)

结论

在本教程中,我们向您展示了如何在Debian 9服务器上安装和保护MySQL服务器。我们还向您展示了如何连接到MySQL Shell以及如何创建新的数据库和表。

现在您的MySQL服务器已启动并正在运行,并且您知道如何从命令行连接到MySQL服务器,您可能需要查看以下指南:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值