在 Ubuntu 中安装 MySQL5.7.20(任意版本)
相关链接:
在 CentOS 1804 中 使用 yum 安装 MySQL 5.7 最新版
在不打开 3306 端口的情况下,使用 Navicat 进项远程连接(使用22端口)
在 CentOS 1804 中 安装 MySQL 5.7.20 (或任意MySQL版本)
本示例使用的安装技术来源于官方文档:
https://dev.mysql.com/doc/mysql-apt-repo-quick-guide/en/
安装准备:
- 安装MySQL5.7.20(或任意版本)时,需要去MySQL官网下载deb包。
- 网址:http://repo.mysql.com/apt/ubuntu/pool/mysql-5.7/m/mysql-community/
- MySQL需要使用的包为(***代表版本号):
- mysql-common***
- mysql-community-client***
- mysql-client***
- mysql-community-server***
- 其中MySQL5.7.20需要的包如下:
- mysql-common_5.7.20-1ubuntu17.10_amd64.deb
- mysql-community-client_5.7.20-1ubuntu17.10_amd64.deb
- mysql-client_5.7.20-1ubuntu17.10_amd64.deb
- mysql-community-server_5.7.20-1ubuntu17.10_amd64.deb
- 特出情况:
- 在安装过程可能会遇见缺少包的情况(本示例使用的是Ubuntu 18.04.01,缺少两个包,分别是libaio1、libmecab2),在安装过程会讲解怎样去下载和安装缺少的包。
- 本示例中需要的4个包,在其他版本中不能保证也是仅仅需要这四个包,最简单粗暴的方法是安装mysql-community-server***,提示缺少哪个包,就去官网(http://repo.mysql.com/apt/ubuntu/pool/mysql-5.7/m/mysql-community/)去下载哪个包,记住一定要是相同版本的。
- 将安装需要的4个包上传至Ubuntu,如图所示:
- 在安装包所在的文件夹执行:
安装第一个包(安装顺序不可更改):[email protected]:/usr/java# dpkg -i mysql-common_5.7.20-1ubuntu17.10_amd64.deb Selecting previously unselected package mysql-common. (Reading database ... 102189 files and directories currently installed.) Preparing to unpack mysql-common_5.7.20-1ubuntu17.10_amd64.deb ... Unpacking mysql-common (5.7.20-1ubuntu17.10) ... Setting up mysql-common (5.7.20-1ubuntu17.10) ... update-alternatives: using /etc/mysql/my.cnf.fallback to provide /etc/mysql/my.cnf (my.cnf) in auto mode [email protected]:/usr/java#
- 安装第二个包:
提示缺少依赖包libaio1:
去阿里云开源镜像站(链接:https://opsx.alibaba.com/mirror)下载在对应的包。[email protected]:/usr/java# dpkg -i mysql-community-client_5.7.20-1ubuntu17.10_amd64.deb Selecting previously unselected package mysql-community-client. (Reading database ... 102204 files and directories currently installed.) Preparing to unpack mysql-community-client_5.7.20-1ubuntu17.10_amd64.deb ... Unpacking mysql-community-client (5.7.20-1ubuntu17.10) ... dpkg: dependency problems prevent configuration of mysql-community-client: mysql-community-client depends on libaio1 (>= 0.3.93); however: Package libaio1 is not installed. dpkg: error processing package mysql-community-client (--install): dependency problems - leaving unconfigured Processing triggers for man-db (2.8.3-2) ... Errors were encountered while processing: mysql-community-client [email protected]:/usr/java#
利用仓库名、发行版、架构进行筛选,下载(基本信息筛选后,下哪个都差不多)后上传至服务器,并进行安装。
让我们在此安装一下第二个包:[email protected]:/usr/java# dpkg -i libaio1_0.3.109-4_amd64.deb Selecting previously unselected package libaio1:amd64. (Reading database ... 102261 files and directories currently installed.) Preparing to unpack libaio1_0.3.109-4_amd64.deb ... Unpacking libaio1:amd64 (0.3.109-4) ... Setting up libaio1:amd64 (0.3.109-4) ... Processing triggers for libc-bin (2.27-3ubuntu1) ...
此时便没有错误了。[email protected]:/usr/java# dpkg -i mysql-community-client_5.7.20-1ubuntu17.10_amd64.deb (Reading database ... 102268 files and directories currently installed.) Preparing to unpack mysql-community-client_5.7.20-1ubuntu17.10_amd64.deb ... Unpacking mysql-community-client (5.7.20-1ubuntu17.10) over (5.7.20-1ubuntu17.10) ... Setting up mysql-community-client (5.7.20-1ubuntu17.10) ... Processing triggers for man-db (2.8.3-2) ... [email protected]:/usr/java#
- 安装第三个包:
[email protected]:/usr/java# dpkg -i mysql-client_5.7.20-1ubuntu17.10_amd64.deb Selecting previously unselected package mysql-client. (Reading database ... 102268 files and directories currently installed.) Preparing to unpack mysql-client_5.7.20-1ubuntu17.10_amd64.deb ... Unpacking mysql-client (5.7.20-1ubuntu17.10) ... Setting up mysql-client (5.7.20-1ubuntu17.10) ... [email protected]:/usr/java#
- 安装第四个包:
由于此时会提示缺少libmecab2,为了减少篇幅,先安装此包:
再安装第四个包:[email protected]:/usr/java# dpkg -i libmecab2_0.996-1.1_amd64.deb Selecting previously unselected package libmecab2. (Reading database ... 102437 files and directories currently installed.) Preparing to unpack libmecab2_0.996-1.1_amd64.deb ... Unpacking libmecab2 (0.996-1.1) ... Setting up libmecab2 (0.996-1.1) ... Processing triggers for libc-bin (2.27-3ubuntu1) ... [email protected]:/usr/java#
安装过程提示设置密码(输入两次一样的,为了确认):[email protected]:/usr/java# dpkg -i mysql-community-server_5.7.20-1ubuntu17.10_amd64.deb (Reading database ... 102445 files and directories currently installed.) Preparing to unpack mysql-community-server_5.7.20-1ubuntu17.10_amd64.deb ... . Unpacking mysql-community-server (5.7.20-1ubuntu17.10) over (5.7.20-1ubuntu17.10) ... Setting up mysql-community-server (5.7.20-1ubuntu17.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. Processing triggers for ureadahead (0.100.0-20) ... Processing triggers for systemd (237-3ubuntu10.3) ... Processing triggers for man-db (2.8.3-2) ... [email protected]:/usr/java#
- 至此已安装完成,本人原创,如需转载,请注明转载地址。
- 什么?你们不相信安装成功了?那我们来试试:
[email protected]:/usr/java# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.20 MySQL Community Server (GPL) Copyright (c) 2000, 2017, 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时的信息已经说明了(在此吐槽一下,网上有很对人问,有很多人说查询MySQL安装版本,你们记住了吗?登录MySQL时不是已经给你提示了什么版本了吗?)。
相关链接:
在 CentOS 1804 中 使用 yum 安装 MySQL 5.7 最新版