Jump to content
IPS Community Suite 简体中文
Sign in to follow this  
ipscn

Connect to MySQL Database on Local Network

Recommended Posts

本文记录访问局域网 MySQL 的设置。

修改用户权限

因为我的 root1 才是 MySQL 的根用户,所以在 phpMySQL 新建一个用户 root,然后赋予它权限。

 mysql -u root1 -p

use mysql;

select user,host from user;

不想新建用户的话,那就

GRANT ALL PRIVILEGES ON database.* TO 'root'@'%' IDENTIFIED BY 'mysql' WITH GRANT OPTION;
FLUSH PRIVILEGES;

 

Share this post


Link to post

MySQL / MariaDB 配置文件

注释掉 bind-address=127.0.0.1

sudo nano /etc/mysql/my.cnf 

如果装的是 MariaDB,那就是

sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

注释掉,保存配置文件,重启 mysql

sudo systemctl restart mysql

防火墙

以 Ubuntu 和 LinuxMint 上的 ufw 为例,添加若干自己用的上的端口

sudo ufw enable
sudo ufw allow 3306
sudo ufw allow 6666
sudo ufw allow 22
sudo ufw allow 21
sudo ufw allow 8888
sudo ufw allow 9999
sudo ufw allow 9901
sudo ufw allow 4200

sudo ufw status

尝试连接

在局域网的机器上尝试连接 MySQL 服务器

mysql -u 用户名 -p密码 -h 服务器IP地址 -P 服务器端MySQL端口号 -D 数据库名

mysql -u root -pmysql -h 192.168.123.236 -P 3306

如果看到

3016.png

就说明连接成功了,如果遇到类似

ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.123.236' (10061)

的错误,排查下前面的设置,有没有错误吧。

 

Share this post


Link to post

其它

ps -Af | grep mysqld

-A – activates selection of all processes

-f – enables full format listing

sudo systemctl restart mysql.service

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×