前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【MySQL 系列】在 Ubuntu 上安装 MySQL

【MySQL 系列】在 Ubuntu 上安装 MySQL

作者头像
栗筝i
发布2024-03-19 09:30:08
2070
发布2024-03-19 09:30:08
举报
文章被收录于专栏:迁移内容迁移内容

Ubuntu 是一个使用非常广泛的 Linux 发行版。Ubuntu Server 则是云上最流行的服务器操作系统。本篇文章中,我们展示了在 Ubuntu 上安装 MySQL 8 的详细步骤。

1、先决条件

请使用 root 用户,或者具有管理员权限的用户登录系统,完成以下操作。

2、在 Ubuntu 中安装 MySQL
2.1、更新软件仓库包索引

执行以下命令更新 Ubuntu 本地软件仓库的包索引。

代码语言:javascript
复制
sudo apt update
2.2、升级本地软件

输入以下命令升级系统:

代码语言:javascript
复制
sudo apt upgrade
2.3、配置 MySQLPPA

在 Ubuntu 中安装 Mysql 最方便方式是用 MySQL 自己的 APT 仓库。 APT 仓库中包含了 MySQL 的服务器和工具相关的软件。我们需要将此 MySQL APT 仓库添加到系统的包源列表中。

使用 wget 命令下载 MySQL APT 仓库包:

代码语言:javascript
复制
wget -c https://repo.mysql.com//mysql-apt-config_0.8.13-1_all.deb

使用 dpkg 命令安装 MySQL APT 仓库包:

代码语言:javascript
复制
sudo dpkg -i mysql-apt-config_0.8.13-1_all.deb
2.4、安装 MySQL

执行以下命令开始安装 MySQL:

代码语言:javascript
复制
sudo apt install mysql-server

这一步会安装一个不安全的 MySQL 服务器。我们将在下一步配置服务器的安全性。

安装完成后,我们先启动 MySQL 服务器:

代码语言:javascript
复制
sudo systemctl start mysql
2.5、MySQL 安全配置

执行以下命令调整 MySQL 服务器的安全性:

代码语言:javascript
复制
sudo mysql_secure_installation

这将会输出:

代码语言:javascript
复制
Securing 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:

这里时问你是否使用密码验证组件。输入 “Y” 并按下回车键。

代码语言:javascript
复制
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:

这是是设置密码验证策略的级别。他提供了 3 个级别:

  • LOW: 密码长度至少 8 位
  • MEDIUM: 密码长度至少 8 位, 由数字、混合大小写的字母和特殊字符组成
  • STRONG: 密码长度至少 8 位, 由数字、混合大小写的字母、特殊字符和字典文件组成

请选择适合你的密码级别。在这里由于是用来开发和测试,我选择 0.

代码语言:javascript
复制
Please set the password for root here.

New password:

Re-enter new password:

在这里,输入两次密码。

代码语言:javascript
复制
Estimated strength of the password: 25
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y

如果你对密码强度满意,输入 Y 和回车键后继续。

代码语言:javascript
复制
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!

在这里,上面所有问题都输入 Y 。然后完成整个配置过程。

2.6、通过 Systemd 管理 MySQL 服务器

安装完成后,MySQL 服务就会自动启动。我们可以通过以下几个命令查看 MySQL 服务的状态,启动、停止、重启 MySQL 服务器:

  • 查看 MySQL 服务器状态: sudo systemctl status mysql
  • 启动 MySQL 服务器: sudo systemctl start mysql
  • 停止 MySQL 服务器: sudo systemctl stop mysql
  • 重启 MySQL 服务器: sudo systemctl restart mysql
  • 配置 MySQL 服务器自启动: sudo systemctl enable mysql
2.7、连接到 MySQL 服务器

请使用以下命令连接到 MySQL 服务器:

代码语言:javascript
复制
mysql -u root -p

然后根据提示输入 root 帐户的密码,并按下回车键。验证通过后,将显示以下输出代表进入了 MySQL 控制台:

代码语言:javascript
复制
mysql>

使用 SHOW DATABASES 显示当前服务器中的所有数据库:

代码语言:javascript
复制
mysql> show databases;

这是输出:

代码语言:javascript
复制
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.05 sec)

上面显示的数据库,是 MySQL 服务器自带数据库。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2024-03-07,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1、先决条件
  • 2、在 Ubuntu 中安装 MySQL
    • 2.1、更新软件仓库包索引
      • 2.2、升级本地软件
        • 2.3、配置 MySQLPPA
          • 2.4、安装 MySQL
            • 2.5、MySQL 安全配置
              • 2.6、通过 Systemd 管理 MySQL 服务器
                • 2.7、连接到 MySQL 服务器
                相关产品与服务
                云数据库 MySQL
                腾讯云数据库 MySQL(TencentDB for MySQL)为用户提供安全可靠,性能卓越、易于维护的企业级云数据库服务。其具备6大企业级特性,包括企业级定制内核、企业级高可用、企业级高可靠、企业级安全、企业级扩展以及企业级智能运维。通过使用腾讯云数据库 MySQL,可实现分钟级别的数据库部署、弹性扩展以及全自动化的运维管理,不仅经济实惠,而且稳定可靠,易于运维。
                领券
                问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档