系統(tǒng)版本:
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.啟動服務(wù)
systemctl start mysql.service
配置遠程登錄
- 使用debian-sys-maint賬號登錄,并設(shè)置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.設(shè)置允許遠程登錄
因為源安裝默認的配置文件綁定的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服務(wù)
systemctl restart mysql.service
看到已經(jīng)生效
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