如何在 Ubuntu 18.04/16.04 上安装 MySQL 8.0如何在 Ubuntu 18.04/16.04 上安装 MySQL 8.0如何在 Ubuntu 18.04/16.04 上安装 MySQL 8.0如何在 Ubuntu 18.04/16.04 上安装 MySQL 8.0
  • 业务
  • 目标
  • 支持
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容

如何在 Ubuntu 18.04/16.04 上安装 MySQL 8.0

发表 admin at 2025年2月28日
类别
  • 未分类
标签

在本指南中,我们将介绍如何在 Ubuntu 18.04 和 16.04 LTS 服务器上安装 MySQL 8.0。如果您有旧版本的 MySQL Server(例如 5.7),您可能需要进行就地升级或转储所有数据、升级包并重新导入所有数据库数据。

在将 MySQL v8.0 下载到 Ubuntu 18.04 或 16.04 服务器之前,您需要添加官方 MySQL Dev apt 存储库。运行以下命令下载存储库配置文件:

sudo apt update
sudo apt-get install wget
wget https://dev.mysql.com/get/mysql-apt-config_0.8.22-1_all.deb

然后在您的 Ubuntu 系统上安装该软件包:

$ sudo dpkg -i mysql-apt-config_0.8.22-1_all.deb
(Reading database ... 60467 files and directories currently installed.)
Preparing to unpack mysql-apt-config_0.8.22-1_all.deb ...
Unpacking mysql-apt-config (0.8.22-1) over (0.8.17-1) ...
Setting up mysql-apt-config (0.8.22-1) ...
Warning: apt-key should not be used in scripts (called from postinst maintainerscript of the package mysql-apt-config)
OK

出现提示时选择版本。

选择<确定>并按键确认版本安装。

添加存储库后,更新 apt 索引并安装 mysql-server:

sudo apt update
sudo apt install mysql-server

所有依赖项都会自动安装:

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libaio1 libmecab2 mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-client mysql-common mysql-community-client mysql-community-client-core mysql-community-client-plugins mysql-community-server
  mysql-community-server-core
The following NEW packages will be installed:
  libaio1 libmecab2 mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-client mysql-common mysql-community-client mysql-community-client-core mysql-community-client-plugins mysql-community-server
  mysql-community-server-core mysql-server
0 upgraded, 13 newly installed, 0 to remove and 38 not upgraded.
Need to get 41.1 MB of archives.
After this operation, 286 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

接受接下来屏幕中的许可协议以开始安装。

设置 MySQL 数据库服务器的 root 密码。

确认您的 root 用户密码。

同意保留兼容性。

选择默认的身份验证插件。

当要求输入 root 密码时,请提供密码并确认进行设置。

确认安装的MySQL服务器版本:

$ apt policy mysql-server
mysql-server:
  Installed: 8.0.28-1ubuntu18.04
  Candidate: 8.0.28-1ubuntu18.04
  Version table:
 *** 8.0.28-1ubuntu18.04 500
        500 http://repo.mysql.com/apt/ubuntu bionic/mysql-8.0 amd64 Packages
        100 /var/lib/dpkg/status
     5.7.37-0ubuntu0.18.04.1 500
        500 http://mirrors.linux教程/ubuntu bionic-updates/main amd64 Packages
        500 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages
     5.7.21-1ubuntu1 500
        500 http://mirrors.linux教程/ubuntu bionic/main amd64 Packages

如果停止使用,您可以启动应用程序:

sudo systemctl enable --now mysql

使用以下命令检查状态:

$ systemctl status mysql
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2022-03-21 21:08:28 UTC; 39s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
 Main PID: 4168 (mysqld)
   Status: "Server is operational"
    Tasks: 38 (limit: 2361)
   CGroup: /system.slice/mysql.service
           └─4168 /usr/sbin/mysqld
 Mar 21 11:15:29 ubuntu-01 systemd[1]: Starting MySQL Community Server…
 Mar 21 11:15:30 ubuntu-01 systemd[1]: Started MySQL Community Server.

测试 MySQL 8.0 数据库功能

您可以通过创建测试数据库来测试数据库服务器是否正常工作:

$ sudo mysql -u root -p
Enter password: <INPUT-PASSWORD-SET-EARLIER>
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.19 MySQL Community Server - GPL
Copyright (c) 2000, 2020, 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> CREATE DATABASE test_db;
Query OK, 1 row affected (0.01 sec)

mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| test_db            |
+--------------------+
5 rows in set (0.01 sec)

mysql> DROP DATABASE test_db;
Query OK, 0 rows affected (0.01 sec)

mysql> EXIT
Bye

安装桌面数据库管理工具

如果您不喜欢使用 MySQL 命令行,那么请考虑安装数据库工具来帮助您。请查看下面我们的指南:

  • 在 Ubuntu/Debian 上安装和配置 DBeaver

要阅读的数据库书籍:

  • 学习 MySQL/MariaDB 数据库的最佳书籍

您还可以查看以下相关文章:

  • 在 Kali Linux 上安装 Metasploit 框架
  • 了解 Linux 文件系统层次结构
©2015-2025 Norria support@alaica.com