ubuntu 极简安装mysql 8并设置远程登录

ubuntu 极简安装mysql 8并设置远程登录

经验文章nimo972025-03-04 11:28:418A+A-

系统版本:
ubuntu 20.04.3
Mysql版本
mysql Ver 8.0.31-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))

安装步骤

1.安装更新源

sudo apt-get update

2.在线安装

sudo apt install mysql-server -y

3.启动服务

 systemctl  start  mysql.service

配置远程登录

  1. 使用debian-sys-maint账号登录,并设置root账号可以远程登录

查看debian-sys-maint账号密码

sudo cat /etc/mysql/debian.cnf

登录mysql

mysql -u debian-sys-maint -p
update user set host='%'  where user='root';

如果需要重置密码可以使用以下命令直接修改root密码

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '新密码'

2.设置允许远程登录
因为源安装默认的配置文件绑定的127.0.0.1的地址,所以不能被远程访问

Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:6010          0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:33060         0.0.0.0:*               LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN     
tcp6       0      0 ::1:6010                :::*                    LISTEN

需要修改配置文件mysqld.cnf

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

注释掉下面的两个配置

#bind-address           = 127.0.0.1
#mysqlx-bind-address    = 127.0.0.1

重启mysql服务

systemctl restart mysql.service

看到已经生效

Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:6010          0.0.0.0:*               LISTEN     
tcp6       0      0 :::3306                 :::*                    LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN     
tcp6       0      0 ::1:6010                :::*                    LISTEN     
tcp6       0      0 :::33060                :::*                    LISTEN  
点击这里复制本文地址 以上内容由nimo97整理呈现,请务必在转载分享时注明本文地址!如对内容有疑问,请联系我们,谢谢!
qrcode

尼墨宝库 © All Rights Reserved.  蜀ICP备2024111239号-7