默认情况下,Ubuntu20.04安装MySQL的版本为8.0。但8.0更加严格的加密规则,使得一些配置难以实现,下面就来为大家介绍在ubuntu20.04中怎么安装MySQL5.7.x。

一、下载安装包(这里以5.7.37为例)

官方下载地址:
https://downloads.mysql.com/archives/community/downloads.mysql.com/archives/community/
选择Ubuntu Linux 18.04 (x86, 64-bit), DEB Bundle
image.png

二、解压安装包

到下载安装包的路径解压安装包

  1. tar -xzf mysql-server_5.7.32-1ubuntu18.04_amd64.deb-bundle.tar

三、安装MySQL5.7.37

1.更新依赖源及安装libaio1、libtinfo5依赖

  1. sudo apt-get install libaio1 -y
  2. sudo apt-get install libtinfo5 -y

2.按下列顺序安装(提示缺少依赖可更换顺序)

  1. sudo dpkg -i mysql-common_5.7.37-1ubuntu18.04_amd64.deb
  2. sudo dpkg-preconfigure mysql-community-server_5.7.37-1ubuntu18.04_amd64.deb #此步需要输入数据的root密码
  3. sudo dpkg -i libmysqlclient20_5.7.37-1ubuntu18.04_amd64.deb
  4. sudo dpkg -i libmysqlclient-dev_5.7.37-1ubuntu18.04_amd64.deb
  5. sudo dpkg -i libmysqld-dev_5.7.37-1ubuntu18.04_amd64.deb
  6. sudo dpkg -i mysql-community-client_5.7.37-1ubuntu18.04_amd64.deb
  7. sudo dpkg -i mysql-client_5.7.37-1ubuntu18.04_amd64.deb
  8. sudo dpkg -i mysql-common_5.7.37-1ubuntu18.04_amd64.deb

3.继续安装依赖

  1. sudo apt-get -f install
  2. sudo apt-get -f install libmecab2 -y

4.安装mysql-server

  1. sudo dpkg -i mysql-community-server_5.7.37-1ubuntu18.04_amd64.deb
  2. sudo dpkg -i mysql-server_5.7.37-1ubuntu18.04_amd64.deb

5.检测安装

  1. mysql -u root -p

Enter password:输入前面设置的密码,就能够进入mysql数据库。
image.png

三、配置MySQL

1.初始化配置

  1. sudo mysql_secure_installation

2.配置说明

  1. #1
  2. VALIDATE PASSWORD PLUGIN can be used to test passwords...
  3. Press y|Y for Yes, any other key for No: N (选择N,不会进行密码的强校验)
  4. #2
  5. Please set the password for root here...
  6. New password: (输入密码)
  7. Re-enter new password: (重复输入)
  8. #3
  9. By default, a MySQL installation has an anonymous user allowing anyone to log into MySQL without having to have a user account created for them...
  10. Remove anonymous users? (Press y|Y for Yes, any other key for No) : N (选择N,不删除匿名用户)
  11. #4
  12. Normally, root should only be allowed to connect from'localhost'. This ensures that someone cannot guess at the root password from the network...
  13. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y (我的选项,选择N,允许root远程连接)
  14. #5
  15. By default, MySQL comes with a database named 'test' that anyone can access...
  16. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N (选择N,不删除test数据库)
  17. #6
  18. Reloading the privilege tables will ensure that all changes made so far will take effect immediately.
  19. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y (选择Y,修改权限立即生效)

3.检查mysql服务状态

  1. systemctl status mysql.service

出现下面界面说明安装成功
image.png
至此MySQL5.7.37已经安装成功。