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 ,还得自己去官网一步一步的进来
- 从官网进到 download 页面后,不要点这个 MySQL APT Repository ,而是要点最右下的那个 Download Archievs
2. 下一步,点 Mysql Community Server
3. 这样就可以看到版本选择的页面了!选择咱需要的 5.7.42, OK!
这里竟然只有 ubuntu 18.04 ,没有 ubuntu 20.04 ?
安装
-
直接复制上图所示的这个 DEB Bundle 的 链接地址
-
因为下载了 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
-
现在就可以安装了!
过程中,可能会遇到 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 installableE: Unable to correct problems, you have held broken packages.
…
修改 root 密码和 host
mysql> use mysqlmysql> 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 tablemysql> 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)
来源地址:https://blog.csdn.net/u010953609/article/details/132201295