ubuntu18.04和20.04(ubuntu focal)安装MySQL8并使用navicat连接(详细)

文章的第一节转载自原文连接

本文实现了服务器ubuntu18.04和虚拟机ubuntu20.04两个版本的MySQL8 的安装,和navicat的连接。其中ubuntu18.04对应第二节,ubuntu20.04是ubuntu focal的,对应第三节。

1. 彻底删除mysql5.7

1.1 查看mysql的依赖项

dpkg --list|grep mysql

在这里插入图片描述

1.2 卸载

sudo apt-get remove mysql-common

在卸载过程中输入yes

1.3 卸载(最后的版本数字根据自己具体的版本进行相应的修改)

sudo apt-get autoremove --purge mysql-server-5.7

1.4 清除残留数据

dpkg -l|grep ^rc|awk '{print$2}'|sudo xargs dpkg -P

出现下图界面,选择<YES>
在这里插入图片描述

1.5 再次查看依赖

dpkg --list|grep mysql

发现有如下残留
在这里插入图片描述

使用命令sudo apt-get autoremove --purge xxxx来卸载:

sudo apt-get autoremove --purge php5.6-mysql

执行之后再次使用命令查看:

dpkg --list|grep mysql

输入命令之后没有任何返回即成功,这里输入了两次:
在这里插入图片描述

2. 服务器(ubuntu18.04)安装MySQL8

2.1 使用命令下载存储库软件包

wget -c https://dev.mysql.com/get/mysql-apt-config_0.8.10-1_all.deb

2.2 使用命令安装上边下载的安装包

sudo dpkg -i mysql-apt-config_0.8.10-1_all.deb

安装过程中提示选择安装版本,默认安装的就是8.0版本,所以直接选择“OK”确认即可;

在这里插入图片描述

2.3 从所有已配置的存储库(包括新添加的 MySQL 8存储库)中下载最新的软件包信息:

sudo apt update

可能的报错:

在这里插入图片描述

解决:

  1. 查看签名列表:

    apt-key list
    

    在这里插入图片描述

  2. 删除过期的签名;(del 后跟上条指令查到的pub)

    sudo apt-key del dsa1024
    
  3. 重新添加新的签名

    GPG error: http://repo.mysql.com/apt/ubuntu focal InRelease: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY 467B942D3A79BD29

    sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 467B942D3A79BD29
    

    在这里插入图片描述

  4. 之后继续执行更新命令:

    sudo apt update
    

    在这里插入图片描述

2.4 安装MySQL8

sudo apt install mysql-server

安装过程中会提示设置root密码。按照提示输入即可;

输入之后会出现选择加密方式的提示界面,我在网上的教程中看到默认的mysql8.0的加密方式与ubuntu18.04 及以上不兼容,所以选择5.x的加密方式;建议选择下边的那个:

2.5 验证成功

mysql -uroot -p

在这里插入图片描述

3. 在Ubuntu 20.04 LTS Focal Fossa上安装MySQL8

在上一节中,执行命令sudo dpkg -i mysql-apt-config_0.8.10-1_all.deb的时候提示这是ubuntu focal系统,这里根据教程来安装。
在这里插入图片描述

Step 1: Update the system to the latest

sudo apt update

Step 2: Install MySQL on Ubuntu 20.04

sudo apt install mysql-server

Step 3: Secure MySQL installation\

sudo mysql_secure_installation

在这里插入图片描述

可能的问题:

设置完密码之后按照要求"Do you wish to continue with the password provided?"输入yes报错如下:

[MySQL Failed! Error: SET PASSWORD has no significance for user ‘root’@’localhost’ as the authentication method used doesn’t store authentication data in the MySQL server. Please consider using ALTER USER](https://www.nixcraft.com/t/mysql-failed-error-set-password-has-no-significance-for-user-root-localhost-as-the-authentication-method-used-doesnt-store-authentication-data-in-the-mysql-server-please-consider-using-alter-user/4233)

解决

  1. Open the terminal application.
  2. Terminate the mysql_secure_installation from another terminal using the killall command:
    sudo killall -9 mysql_secure_installation
  3. Start the mysql client:
    sudo mysql
  4. Run the following SQL query:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'SetRootPasswordHere';
exit
  1. Then run the following command to secure it:
    sudo mysql_secure_installation

  2. When promoted for the password enter the SetRootPasswordHere (or whatever you set when you ran the above SQL query)

  3. That is all.

成功界面如下:
在这里插入图片描述

Step 4: Test MySQL Community Server service

systemctl status mysql.service

在这里插入图片描述

mysql -uroot -p

在这里插入图片描述

4. navicat 连接

4.1 连接报错1103

[图片]

**原因:**帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改”mysql” 数据库里的 “user” 表里的 “host”项,从”localhost”改称”%”

在虚拟机/服务器上进入mysql:

  1. use mysql;
  2. select host, user from user;
  3. update user set host = '%' where user = 'root';
  4. flush privileges;
  5. service mysql restart

4.2 连接报错2003

  1. 在windows下,cmd 输入
telnet  192.168.xxx.xxx 3306
  1. 在虚拟机下输入
netstat -anp| grep 3306

在这里插入图片描述

  1. 修改/etc/mysql/mysql.conf.d/mysqld.cnf

需要root权限,sudo passwd root设置root密码, su进入root.

vim /etc/mysql/mysql.conf.d/mysqld.cnf

把 bind-address = 127.0.0.1 改为 bind-address = 0.0.0.0

上面的意思是改为监听所有地址

  1. 重启MySQL
service mysql restart
  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值