如何在Debian 10/Debian 9上安装MySQL 8.0

时间:2020-02-23 14:40:57  来源:igfitidea点击:

本教程旨在在Debian 10/Debian 9上安装MySQL8. 本教程适用于在Debian 10/9上全新安装MySQL 8.0。如果我们使用的是旧版的MySQL Server(例如5.7),则需要进行就地升级或者转储所有数据,升级软件包并将所有数据库数据重新导入MySQL 8.0。

请按照以下步骤在Debian 9/Debian 8上安装MySQL 8.0。

添加MySQL Dev apt存储库

MySQL 8.0软件包可在官方的MySQL Dev apt存储库中获得。

sudo apt -y  install wget
wget https://repo.mysql.com//mysql-apt-config_0.8.13-1_all.deb
sudo dpkg -i mysql-apt-config_0.8.13-1_all.deb

同意配置MySQL Apt存储库。

出现提示时,确认默认添加MySQL 8.0存储库。

然后按Tab键选择<确定>,然后按<Enter>键以确认版本安装。

在Debian 10/Debian 9上安装MySQL 8.0

添加存储库后,通过运行以下命令在Debian 10/Debian 9上安装MySQL 8.0:

sudo apt update
sudo apt -y install mysql-server

当要求输入" root"密码时,请提供密码。

重新输入根数据库用户密码。

选择Authentication插件,然后选择<确定>以完成在Debian 10/Debian 9上的MySQL 8.0安装。

检查使用apt-policy命令安装的版本:

$apt policy mysql-server
mysql-server:
  Installed: 8.0.13-1debian9
  Candidate: 8.0.13-1debian9
  Version table:
 *** 8.0.13-1debian9 500
        500 http://repo.mysql.com/apt/debian stretch/mysql-8.0 amd64 Packages
        100 /var/lib/dpkg/status
     5.5.9999+default 500
        500 http://httpredir.debian.org/debian stretch/main amd64 Packages

mysql服务应默认启动,我们可以使用以下命令确认服务状态:

$sudo systemctl status is-enabled mysql
Unit is-enabled.service could not be found.
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2016-11-24 11:26:34 UTC; 1min 54s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 1917 ExecStartPre=/usr/share/mysql-8.0/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 1952 (mysqld)
   Status: "SERVER_OPERATING"
    Tasks: 37 (limit: 4915)
   CGroup: /system.slice/mysql.service
           └─1952 /usr/sbin/mysqld

Nov 24 11:26:33 deb9 systemd[1]: Starting MySQL Community Server...
Nov 24 11:26:34 deb9 systemd[1]: Started MySQL Community Server.

在Debian 9/Debian 8上测试MySQL 8.0安装

让我们进行测试以确认Debian 10/Debian 9上安装的MySQL 8.0是否按预期工作。

以root用户身份使用创建的密码登录:

$mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.13 MySQL Community Server - GPL

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names Jan be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SELECT VERSION();
+-----------+
| VERSION() |
+-----------+
| 8.0.13    |
+-----------+
1 row in set (0.00 sec)

创建一个测试数据库和用户。

CREATE USER 'test_user'@'localhost' IDENTIFIED BY "Jek1oleiboafei4eeghu";
CREATE DATABASE test_db;
GRANT ALL PRIVILEGES ON test_db.* TO 'test_user'@'localhost';
FLUSH PRIVILEGES;
QUIT

尝试以test_user身份访问数据库控制台:

$mysql -u test_user -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.13 MySQL Community Server - GPL

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names Jan be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

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

mysql> QUIT

一旦确认能够登录并使用分配的数据库,请以root用户身份再次登录并删除测试数据库和用户。

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

mysql> DROP USER 'test_user'@'localhost';
Query OK, 0 rows affected (0.11 sec)

mysql> SELECT USER FROM mysql.user;
+------------------+
| USER             |
+------------------+
| mysql.infoschema |
| mysql.session    |
| mysql.sys        |
| root             |
+------------------+
4 rows in set (0.00 sec)

mysql> QUIT
Bye

安装桌面数据库管理工具

如果我们不喜欢使用MySQL命令行,请考虑安装和配置DBeaver