ubuntu环境快速安装mysql
1、环境准备
因为默认安装的源的地址都是国外地址,有时是被防火墙拦截,有时是速度太慢,有时是有些安装包在上面根本就找不到,所以需要替换成国内的源。
1.1先将之前的源列表文件备份
先备份sources.list文件,执行命令:cp /etc/apt/sources.list /etc/apt/sources.list-bak回车
1.2、修改sources.list文件
该文件路径为:/etc/apt/sources.list,此文件的内容和系统版本有关,下面的内容适用于ubuntu16.04系统,使用下面的内容替换该文件的原有内容。deb http://mirrors.aliyun.com/ubuntu/ xenial main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/xenial main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main multiverse restricted universe
1.3、执行更新命令
apt-get update
2、下载安装包
wget --no-check-certificate https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-server_5.7.29-1ubuntu16.04_amd64.deb-bundle.tar
3、解压安装包
tar -xvf mysql-server_5.7.29-1ubuntu16.04_amd64.deb-bundle.tar -C mysql
mysql-common_5.7.29-1ubuntu16.04_amd64.deb
libmysqld-dev_5.7.29-1ubuntu16.04_amd64.deb
mysql-testsuite_5.7.29-1ubuntu16.04_amd64.deb
mysql-community-source_5.7.29-1ubuntu16.04_amd64.deb
mysql-server_5.7.29-1ubuntu16.04_amd64.deb
libmysqlclient-dev_5.7.29-1ubuntu16.04_amd64.deb
mysql-client_5.7.29-1ubuntu16.04_amd64.deb
mysql-community-test_5.7.29-1ubuntu16.04_amd64.deb
libmysqlclient20_5.7.29-1ubuntu16.04_amd64.deb
mysql-community-server_5.7.29-1ubuntu16.04_amd64.deb
mysql-community-client_5.7.29-1ubuntu16.04_amd64.deb
4、升级并安装一些依赖项
apt-get -f upgrade
5、安装一系列mysql包
dpkg -i mysql-common_5.7.29-1ubuntu16.04_amd64.deb
dpkg -i libmysqlclient20_5.7.29-1ubuntu16.04_amd64.deb
dpkg -i libmysqlclient-dev_5.7.29-1ubuntu16.04_amd64.deb
dpkg -i libmysqld-dev_5.7.29-1ubuntu16.04_amd64.deb
dpkg -i mysql-community-client_5.7.29-1ubuntu16.04_amd64.deb
dpkg -i mysql-client_5.7.29-1ubuntu16.04_amd64.deb
dpkg -i mysql-community-source_5.7.29-1ubuntu16.04_amd64.debdpkg -i mysql-community-server_5.7.29-1ubuntu16.04_amd64.deb
如果报错:
Unpacking mysql-community-server (5.7.29-1ubuntu16.04) over (5.7.29-1ubuntu16.04) ...
dpkg: dependency problems prevent configuration of mysql-community-server:
mysql-community-server depends on libmecab2 (>= 0.996-1.2ubuntu1); however:
Package libmecab2 is not installed.解决方法:
sudo apt-get -f install
dpkg -i mysql-community-server_5.7.29-1ubuntu16.04_amd64.deb
(Reading database ... 275172 files and directories currently installed.)
Preparing to unpack mysql-community-server_5.7.29-1ubuntu16.04_amd64.deb ...
.
Unpacking mysql-community-server (5.7.29-1ubuntu16.04) over (5.7.29-1ubuntu16.04) ...
dpkg: dependency problems prevent configuration of mysql-community-server:
mysql-community-server depends on libmecab2 (>= 0.996-1.2ubuntu1); however:
Package libmecab2 is not installed.
解决方法:
apt-get -f upgrade
6、查看版本
root@ubuntu:/home/mysql#mysql -V
mysql Ver 14.14 Distrib 5.7.29, for Linux (x86_64) using EditLine wrapper
7、验证安装是否可以正常使用
root@ubuntu:/home/mysql#mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.29 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> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changed