apt-get upgrade apt-get update
apt-get install mysql-server
service mysql start
service mysql status
netstat -tap | grep mysql
mysql -u root -p
use mysql; select Host,User from user;
CREATE USER 'test'@'192.XXX.XXX.XX' IDENTIFIED WITH mysql_native_password BY '123@#$';
其中:
test
为数据库用户名192.XXX.XXX.XX
为远程连接的IP地址,即可访问IP地址mysql_native_password
为加密规则123@#$
为数据库登录密码GRANT ALL PRIVILEGES ON *.* TO 'test'@'192.XXX.XXX.XX';
指定权限则将ALL
改为SELECT DELETE UPDATE INSERT
等权限即可
FLUSH PRIVILEGES;
drop user 'test'@'192.XXX.XXX.XX';
Lost connection to server at "handshake: reading initial communication packet"
修改思路如下:查看防火墙 - ping通 - 查看端口 - 设置数据库访问域
sudo iptables -L -n
Unit iptables.service could not be found.
参考博主解法:解决 Ubuntu20.04 中的 Unit iptables.service not found 及 Unit file iptables.service does not exist 问题
原因:Ubuntu20.04中使用iptables-persistent进行管理,其能保存安全策略并在重新开机时读取。
下载软件包
apt-get install iptables-persistent
systemctl status iptables
systemctl start iptables
systemctl stop iptables
【附:如何将端口与防火墙配合开放还待学习…因此,直接查看防火墙状态,关闭防火墙了】
Test-NetConnection -ComputerName 192.168.XXX.XX -Port 3306
netstat -nltp | grep mysql
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 2919/mysqld
vim /etc/mysql/mysql.conf.d/mysqld.cnf
Host '192.XXX.XXX.XX' is not allowed to connect to this MySQL server.