Ubuntu21.10 安装 MySQL8.+

本文将介绍怎样在 Ubuntu21.10 版本中安装 MySQL8.+ 数据库

下载安装包

进入 MySQL 官网,下载 Ubuntu Linux 21.10 (x86, 64-bit) 版本的 MySQL 安装包。命令如下:

hxstrive@course:~/Desktop$ wget https://cdn.mysql.com/archives/mysql-8.0/mysql-server_8.0.27-1ubuntu21.10_amd64.deb-bundle.tar
--2022-03-16 13:02:53--  https://cdn.mysql.com/archives/mysql-8.0/mysql-server_8.0.27-1ubuntu21.10_amd64.deb-bundle.tar
Resolving cdn.mysql.com (cdn.mysql.com)... 23.56.1.19
Connecting to cdn.mysql.com (cdn.mysql.com)|23.56.1.19|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 297881600 (284M) [application/x-tar]
Saving to: ‘mysql-server_8.0.27-1ubuntu21.10_amd64.deb-bundle.tar’

mysql-server_8.0.27-1ubuntu2 100%[==============================================>] 284.08M  6.05MB/s    in 89s     

2022-03-16 13:04:23 (3.20 MB/s) - ‘mysql-server_8.0.27-1ubuntu21.10_amd64.deb-bundle.tar’ saved [297881600/297881600]

解压安装包

使用命令解压安装包,注意,这里没有使用 -z 选项,因为安装包没有使用 zip 进行压缩。命令如下:

hxstrive@course:~/Desktop$ tar -xvf mysql-server_8.0.27-1ubuntu21.10_amd64.deb-bundle.tar 
libmysqlclient-dev_8.0.27-1ubuntu21.10_amd64.deb
libmysqlclient21_8.0.27-1ubuntu21.10_amd64.deb
mysql-client_8.0.27-1ubuntu21.10_amd64.deb
mysql-common_8.0.27-1ubuntu21.10_amd64.deb
mysql-community-client-core_8.0.27-1ubuntu21.10_amd64.deb
mysql-community-client-plugins_8.0.27-1ubuntu21.10_amd64.deb
mysql-community-client_8.0.27-1ubuntu21.10_amd64.deb
mysql-community-server-core_8.0.27-1ubuntu21.10_amd64.deb
mysql-community-server-debug_8.0.27-1ubuntu21.10_amd64.deb
mysql-community-server_8.0.27-1ubuntu21.10_amd64.deb
mysql-community-test-debug_8.0.27-1ubuntu21.10_amd64.deb
mysql-community-test_8.0.27-1ubuntu21.10_amd64.deb
mysql-server_8.0.27-1ubuntu21.10_amd64.deb
mysql-testsuite_8.0.27-1ubuntu21.10_amd64.deb

安装依赖

运行如下命令安装 libaio1 和 libmecab2 第三方依赖库。如下:

hxstrive@course:~/Desktop$ sudo apt-get install libaio1 libmecab2
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  libaio1 libmecab2
0 upgraded, 2 newly installed, 0 to remove and 9 not upgraded.
2 not fully installed or removed.
Need to get 206 kB of archives.
After this operation, 910 kB of additional disk space will be used.
Get:1 http://cn.archive.ubuntu.com/ubuntu impish/main amd64 libaio1 amd64 0.3.112-9ubuntu1 [6,972 B]
Get:2 http://cn.archive.ubuntu.com/ubuntu impish/main amd64 libmecab2 amd64 0.996-14build4 [199 kB]
Fetched 206 kB in 32s (6,476 B/s)                                                                                  
Selecting previously unselected package libaio1:amd64.
(Reading database ... 161808 files and directories currently installed.)
Preparing to unpack .../libaio1_0.3.112-9ubuntu1_amd64.deb ...
Unpacking libaio1:amd64 (0.3.112-9ubuntu1) ...
Selecting previously unselected package libmecab2:amd64.
Preparing to unpack .../libmecab2_0.996-14build4_amd64.deb ...
Unpacking libmecab2:amd64 (0.996-14build4) ...
Setting up libmecab2:amd64 (0.996-14build4) ...
Setting up mysql-client (8.0.27-1ubuntu21.10) ...
Setting up libaio1:amd64 (0.3.112-9ubuntu1) ...
Setting up mysql-community-server-core (8.0.27-1ubuntu21.10) ...
Processing triggers for libc-bin (2.34-0ubuntu3.2) ...

安装 MySQL

上面将安装包解压后出现了很多 deb 后缀的安装包。此时,执行这些安装顺序将变得非常重要,因为它们之间存在依赖关系,安装顺序如下:

  1. mysql-common_8.0.27-1ubuntu21.10_amd64.deb 

  2. mysql-community-client-plugins_8.0.27-1ubuntu21.10_amd64.deb 

  3. libmysqlclient21_8.0.27-1ubuntu21.10_amd64.deb 

  4. libmysqlclient-dev_8.0.27-1ubuntu21.10_amd64.deb 

  5. mysql-community-client-core_8.0.27-1ubuntu21.10_amd64.deb 

  6. mysql-community-client-plugins_8.0.27-1ubuntu21.10_amd64.deb 

  7. mysql-community-client_8.0.27-1ubuntu21.10_amd64.deb 

  8. mysql-community-server-core_8.0.27-1ubuntu21.10_amd64.deb 

  9. mysql-community-server_8.0.27-1ubuntu21.10_amd64.deb 

  10. mysql-server_8.0.27-1ubuntu21.10_amd64.deb

安装 mysql-common_8.0.27-1ubuntu21.10_amd64.deb

hxstrive@course:~/Desktop$ sudo dpkg -i mysql-common_8.0.27-1ubuntu21.10_amd64.deb 
(Reading database ... 161663 files and directories currently installed.)
Preparing to unpack mysql-common_8.0.27-1ubuntu21.10_amd64.deb ...
Unpacking mysql-common (8.0.27-1ubuntu21.10) over (8.0.27-1ubuntu21.10) ...
Setting up mysql-common (8.0.27-1ubuntu21.10) ...

安装 mysql-community-client-plugins_8.0.27-1ubuntu21.10_amd64.deb 

hxstrive@course:~/Desktop$ sudo dpkg -i mysql-community-client-plugins_8.0.27-1ubuntu21.10_amd64.deb 
Selecting previously unselected package mysql-community-client-plugins.
(Reading database ... 161663 files and directories currently installed.)
Preparing to unpack mysql-community-client-plugins_8.0.27-1ubuntu21.10_amd64.deb ...
Unpacking mysql-community-client-plugins (8.0.27-1ubuntu21.10) ...
Setting up mysql-community-client-plugins (8.0.27-1ubuntu21.10) ...
Processing triggers for libc-bin (2.34-0ubuntu3.2) ...

安装 libmysqlclient21_8.0.27-1ubuntu21.10_amd64.deb 

hxstrive@course:~/Desktop$ sudo dpkg -i libmysqlclient21_8.0.27-1ubuntu21.10_amd64.deb 
(Reading database ... 161677 files and directories currently installed.)
Preparing to unpack libmysqlclient21_8.0.27-1ubuntu21.10_amd64.deb ...
Unpacking libmysqlclient21:amd64 (8.0.27-1ubuntu21.10) over (8.0.27-1ubuntu21.10) ...
Setting up libmysqlclient21:amd64 (8.0.27-1ubuntu21.10) ...
Processing triggers for libc-bin (2.34-0ubuntu3.2) ...

安装 libmysqlclient-dev_8.0.27-1ubuntu21.10_amd64.deb 

hxstrive@course:~/Desktop$ sudo dpkg -i libmysqlclient-dev_8.0.27-1ubuntu21.10_amd64.deb 
(Reading database ... 161677 files and directories currently installed.)
Preparing to unpack libmysqlclient-dev_8.0.27-1ubuntu21.10_amd64.deb ...
Unpacking libmysqlclient-dev (8.0.27-1ubuntu21.10) over (8.0.27-1ubuntu21.10) ...
Setting up libmysqlclient-dev (8.0.27-1ubuntu21.10) ...
Processing triggers for man-db (2.9.4-2) ...

安装 mysql-community-client-core_8.0.27-1ubuntu21.10_amd64.deb 

hxstrive@course:~/Desktop$ sudo dpkg -i mysql-community-client-core_8.0.27-1ubuntu21.10_amd64.deb 
(Reading database ... 161683 files and directories currently installed.)
Preparing to unpack mysql-community-client-core_8.0.27-1ubuntu21.10_amd64.deb ...
Unpacking mysql-community-client-core (8.0.27-1ubuntu21.10) over (8.0.27-1ubuntu21.10) ...
Setting up mysql-community-client-core (8.0.27-1ubuntu21.10) ...
Processing triggers for man-db (2.9.4-2) ...

安装 mysql-community-client-plugins_8.0.27-1ubuntu21.10_amd64.deb 

hxstrive@course:~/Desktop$ sudo dpkg -i mysql-community-client-plugins_8.0.27-1ubuntu21.10_amd64.deb 
(Reading database ... 161683 files and directories currently installed.)
Preparing to unpack mysql-community-client-plugins_8.0.27-1ubuntu21.10_amd64.deb ...
Unpacking mysql-community-client-plugins (8.0.27-1ubuntu21.10) over (8.0.27-1ubuntu21.10) ...
Setting up mysql-community-client-plugins (8.0.27-1ubuntu21.10) ...
Processing triggers for libc-bin (2.34-0ubuntu3.2) ...

安装 mysql-community-client_8.0.27-1ubuntu21.10_amd64.deb 

hxstrive@course:~/Desktop$ sudo dpkg -i mysql-community-client_8.0.27-1ubuntu21.10_amd64.deb 
(Reading database ... 161683 files and directories currently installed.)
Preparing to unpack mysql-community-client_8.0.27-1ubuntu21.10_amd64.deb ...
Unpacking mysql-community-client (8.0.27-1ubuntu21.10) over (8.0.27-1ubuntu21.10) ...
Setting up mysql-community-client (8.0.27-1ubuntu21.10) ...
Processing triggers for man-db (2.9.4-2) ...

安装 mysql-community-server-core_8.0.27-1ubuntu21.10_amd64.deb 

hxstrive@course:~/Desktop$ sudo dpkg -i mysql-community-server-core_8.0.27-1ubuntu21.10_amd64.deb 
(Reading database ... 161819 files and directories currently installed.)
Preparing to unpack mysql-community-server-core_8.0.27-1ubuntu21.10_amd64.deb ...
Unpacking mysql-community-server-core (8.0.27-1ubuntu21.10) over (8.0.27-1ubuntu21.10) ...
Setting up mysql-community-server-core (8.0.27-1ubuntu21.10) ...
Processing triggers for libc-bin (2.34-0ubuntu3.2) ...
Processing triggers for man-db (2.9.4-2) ...

安装 mysql-community-server_8.0.27-1ubuntu21.10_amd64.deb

hxstrive@course:~/Desktop$ sudo dpkg -i mysql-community-server_8.0.27-1ubuntu21.10_amd64.deb 
Selecting previously unselected package mysql-community-server.
(Reading database ... 161819 files and directories currently installed.)
Preparing to unpack mysql-community-server_8.0.27-1ubuntu21.10_amd64.deb ...
Unpacking mysql-community-server (8.0.27-1ubuntu21.10) ...
Setting up mysql-community-server (8.0.27-1ubuntu21.10) ...
update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /lib/systemd/system/mysql.service.

在安装该安装包的过程中,将跳转到如下页面。使用该页面给 root 账号设置访问密码,如下图:

Ubuntu21.10 安装 MySQL8.+

密码输入完成后,使用 tab 键跳转到“<ok>”按钮。将再次跳转到配置页面,配置密码存储加密方式,如下图:

Ubuntu21.10 安装 MySQL8.+

使用 tab 键跳转到“<ok>”按钮保存配置信息。

安装 mysql-server_8.0.27-1ubuntu21.10_amd64.deb 

hxstrive@course:~/Desktop$ sudo dpkg -i mysql-server_8.0.27-1ubuntu21.10_amd64.deb 
Selecting previously unselected package mysql-server.
(Reading database ... 161838 files and directories currently installed.)
Preparing to unpack mysql-server_8.0.27-1ubuntu21.10_amd64.deb ...
Unpacking mysql-server (8.0.27-1ubuntu21.10) ...
Setting up mysql-server (8.0.27-1ubuntu21.10) ...

验证 MySQL 是否已启动

默认情况下,MySQL安装完后,会自动启动。运行下面命令查看 mysql 是否启动:

hxstrive@course:~/Desktop$ netstat -tap | grep mysql
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp6       0      0 [::]:mysql              [::]:*                  LISTEN      -

登录 MySQL

使用 mysql 命令验证是否可以成功登录到 MySQL。命令如下:

hxstrive@course:~/Desktop$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.27 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql>
一寸光阴一寸金,寸金难买寸光阴。——《增广贤文》
0 不喜欢
说说我的看法 -
全部评论(
没有评论
关于
本网站属于个人的非赢利性网站,转载的文章遵循原作者的版权声明,如果原文没有版权声明,请来信告知:hxstrive@outlook.com
公众号