Ubuntu 20.04 直接 apt 安装的 mysql 是 8.0 ,现在需要安装 5.7 版本,还颇费周章!按照文档直接点进去那个 MySQL APT Repository 中(https://dev.mysql.com/downloads/repo/apt/)只显示了 8.0 ,没有其他版本的 Repository !

在这里插入图片描述

查找 mysql 5.7 的 Repository

如果需要找到 5.7 的 Repository ,还得自己去官网一步一步的进来

  1. 从官网进到 download 页面后,不要点这个 MySQL APT Repository ,而是要点最右下的那个 Download Archievs

在这里插入图片描述
2. 下一步,点 Mysql Community Server
在这里插入图片描述
3. 这样就可以看到版本选择的页面了!选择咱需要的 5.7.42, OK!

这里竟然只有 ubuntu 18.04 ,没有 ubuntu 20.04 ?

安装

  1. 直接复制上图所示的这个 DEB Bundle 的 链接地址

  2. 因为下载了 bundle ,里面包含了mysql server 和其他工具的 .deb包,所以,单独建一个目录比较好

    $ mkdir -p mysql-5.7

    $ cd mysql-5.7/

    ~/mysql-5.7$ wget https://downloads.mysql.com/archives/get/p/23/file/mysql-server_5.7.42-1ubuntu18.04_amd64.deb-bundle.tar

    $ tar xvf mysql-server_5.7.42-1ubuntu18.04_amd64.deb-bundle.tar

     libmysqlclient20_5.7.42-1ubuntu18.04_amd64.deb
     libmysqlclient-dev_5.7.42-1ubuntu18.04_amd64.deb
     libmysqld-dev_5.7.42-1ubuntu18.04_amd64.deb
     mysql-client_5.7.42-1ubuntu18.04_amd64.deb
     mysql-common_5.7.42-1ubuntu18.04_amd64.deb
     mysql-community-client_5.7.42-1ubuntu18.04_amd64.deb
     mysql-community-server_5.7.42-1ubuntu18.04_amd64.deb
     mysql-community-source_5.7.42-1ubuntu18.04_amd64.deb
     mysql-community-test_5.7.42-1ubuntu18.04_amd64.deb
     mysql-server_5.7.42-1ubuntu18.04_amd64.deb
     mysql-testsuite_5.7.42-1ubuntu18.04_amd64.deb
    
  3. 现在就可以安装了!

    过程中,可能会遇到 mysql-client : Depends: mysql-community-client (= 5.7.42-1ubuntu18.04) but it is not installable 之类的错误,根据我的经验,干脆反过来,直接安装 mysql-server_5.7.42-1ubuntu18.04_amd64.deb ,然后,按照错误提示一个一个的补充完整!、

$ sudo apt-get install ./mysql-server_5.7.42-1ubuntu18.04_amd64.deb

...
The following packages have unmet dependencies:
 mysql-server : Depends: mysql-community-server (= 5.7.42-1ubuntu18.04) but it is not installable
E: Unable to correct problems, you have held broken packages.

修改 root 密码和 host

mysql> use mysql

mysql> update user set host = '%' where user = 'root';

直接修改密码不行?
mysql> SET PASSWORD FOR 'root'@'%' = PASSWORD('XXXXXXXX');
ERROR 1133 (42000): Can't find any matching row in the user table

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.11 sec)

mysql> SET PASSWORD FOR 'root'@'%' = PASSWORD('XXXXXXXX');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> select user,host from user;
+---------------+-----------+
| user          | host      |
+---------------+-----------+
| root          | %         |
| mysql.session | localhost |
| mysql.sys     | localhost |
+---------------+-----------+
3 rows in set (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.11 sec)
Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐