debian mysql远程访问权限_设置 Linux 服务器中 MySQL 允许远程访问

开启 MySQL 远程访问权限: 在linux系统上登陆mysql服务。

-- root 是用户名

[root@localhost ~]# mysql -u root -p

Enter password: -- 输入密码

创建远程连接 MySQL 的用户:

-- 创建用户、密码及权限范围 第一个 roo t为用户名 @后为适用的主机,‘%’表示所有电脑都可以访问连接,第二个 root 为密码

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.0.2' IDENTIFIED BY 'root' WITH GRANT OPTION;

Query OK, 0 rows affected (1.57 sec)

-- 立即生效

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

数据库用户操作:

-- 使用 mysql 库

mysql> use mysql;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

-- 查看用户

mysql> select host,user from user;

+-----------+------------------+

| host      | user             |

+-----------+------------------+

| %         | lys              |

| %         | mcAdmin          |

| %         | root             |

| %         | zcbox            |

| localhost | debian-sys-maint |

| localhost | mysql.session    |

| localhost | mysql.sys        |

| localhost | phpmyadmin       |

+-----------+------------------+

8 rows in set (0.00 sec)

-- 更改用户权限:

mysql> update user set host = 'localhost' where user = 'mcAdmin';

Query OK, 1 row affected (0.00 sec)

Rows matched: 1 Changed: 1 Warnings: 0

-- 删除用户:

mysql> delete from user where user = 'mcAdmin';

Query OK, 1 row affected (0.00 sec)

-- 立即生效

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

可见user实际上是一个表,对其操作与普通的mysql操作没有什么不同。

此时旧版的mysql,就已经让数据库可以外部访问了

但在mysql5.7中,上面操作可能仍然不能让你外部访问本地服务器数据库,因为5.7中MySQL的配置文件里默认也是仅允许本地访问

所以还要修改MySQL的配置文件

一般来说在路径/etc/mysql/mysql.conf.d/mysqld.cnf下

通过vi/vim/gedit等编辑器打开此文件

注释掉 bind-address          = 127.0.0.1

然后 sudo service mysql restart 重启mysql

搞定!

查看端口:

mysql> show global variables like 'port';

+---------------+-------+

| Variable_name | Value |

+---------------+-------+

| port | 3306 |

+---------------+-------+

1 row in set (0.01 sec)

貌似还有可能是3306端口的问题,配置文件中也有看到port = 3306 这一行,但是没影响就先不管了;

遇到了再解决

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值