Linux系统(ubuntu20.04TLS)安装mysql8.0.X版,如何进行远程访问设置

一、检查系统是否已安装其他版本mysql

打开系统终端, 执行如下命令,检查系统是否已安装mysql

ps -ef | grep mysql  

出现红色mysql 即已安装mysql

 若已安装mysql,最好把下面卸载清理命令都执行一遍:

        sudo apt-get -y update 
        sudo apt-get -y autoremove --purge mysql-server
        sudo apt-get -y remove mysql-server         # 没用到,已经没有mysql-server
        sudo apt-get -y autoremove mysql-server     # 没用到,已经没有mysql-server
        sudo apt-get -y remove mysql-common
        
        sudo rm /var/lib/apt/lists/lock
        sudo rm /var/cache/apt/archives/lock
        sudo rm -rf /etc/mysql/  /var/lib/mysql    #删除Mysql数据文件夹 
    
        #清理残留数据
        dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P  
        sudo apt -y  autoremove
        sudo apt -y  autoclean
        
        sudo apt-get -y remove mysql-client-5.7
        sudo apt-get -y remove mysql-server-5.7
        sudo apt-get -y remove mysql-client-core-5.7

        sudo apt-get -y autoremove
        sudo apt-get -y --purge remove && sudo apt-get -y autoclean
        sudo apt-get -f -y install
        
        sudo dpkg-reconfigure -a
        sudo dpkg --configure -a    
        sudo apt-get -y update
        sudo apt-get -y upgrade

二、重新安装mysql8.o.x

方式一:在线安装,执行如下命令,

sudo apt-get update

sudo apt-get install mysql-server

方式二:离线安装,需要提前下载好需要的安装包

我个人在用的脚本:

#!/bin/bash
echo -e "正在执行离线安装mysql-8.0"

sudo apt-get -f -y install

#apt-get install libaio1
dpkg -i libaio1_0.3.112-9ubuntu1_amd64.deb

#apt-get install libmecab2
dpkg -i libmecab2_0.996-14build3_amd64.deb

sudo apt-get -f -y install

dpkg -i mysql-community-client-plugins_8.0.25-1ubuntu16.04_amd64.deb
dpkg -i mysql-community-client-core_8.0.25-1ubuntu16.04_amd64.deb
dpkg -i mysql-common_8.0.25-1ubuntu16.04_amd64.deb
dpkg -i mysql-community-client_8.0.25-1ubuntu16.04_amd64.deb


dpkg -i libmysqlclient21_8.0.25-1ubuntu16.04_amd64.deb
dpkg -i libmysqlclient-dev_8.0.25-1ubuntu16.04_amd64.deb
dpkg -i mysql-client_8.0.25-1ubuntu16.04_amd64.deb

dpkg -i mysql-community-server-core_8.0.25-1ubuntu16.04_amd64.deb      
dpkg -i mysql-community-server_8.0.25-1ubuntu16.04_amd64.deb       #设置密码 #选择加密方式
dpkg -i mysql-community-server_8.0.25-1ubuntu16.04_amd64.deb

service mysql restart
service mysql status

注:把以上脚本复制在text文件内,以sctipt.sh命名,然后执行即可

三、初始化Mysql配置

执行如下命令:

sudo mysql_secure_installation

终端输出如下这些命令,对照选择操作即可:

#1
VALIDATE PASSWORD PLUGIN can be used to test passwords...
Press y|Y for Yes, any other key for No: N 
 
#2
Please set the password for root here...
New password: 输入你需要设置的密码
Re-enter new password: 重复输入你需要设置的密码
 
#3
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...
Remove anonymous users? (Press y|Y for Yes, any other key for No) : N 
 
#4
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network...
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y 
 
#5
By default, MySQL comes with a database named 'test' that
anyone can access...
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N 
 
#6
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y 

四、重启服务    systemctl restartmysql.service

        查看服务状态     systemctl status mysql.service    

mysql服务正常:

五、配置远程访问
打开终端,以root用户登录mysql,命令执行如下:

mysql -uroot -p你的数据库密码

#登录成功之后,输入

use mysql; 

#新建用户

create user 'test'@'%' identified by '你的数据库密码';
#授权

GRANT ALL PRIVILEGES ON *.* TO 'test'@'%';
#刷新权限

flush privileges;
#授权远程

ALTER USER 'test'@'%' IDENTIFIED WITH mysql_native_password BY '你的数据库密码';

#刷新权限

flush privileges;
然后,输入exit 退出

六、修改 mysql 的配置文件
以root权限打开终端,   执行命令:

vim  /etc/mysql/mysql.conf.d

查找 “bind-address = 127.0.0.1” ,注释掉

在下面一行复制上一行内容,并修改为 bind-address = 0.0.0.0

改好之后保存配置即可;

然后重启一下mysql服务

systemctl restart   mysql.service

显示状态正常,就可以用数据库管理工具连接和远程操作了

常用Navicat Premium 

新建连接,输入系统主机ip、端口和用户名、密码

 测试连接

 成功咯!

如若本文章对您有帮助,请点个小赞,创作不易,以示鼓励!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

搬砖的小猴

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值