mysql远程连接

多人开发时,每人一份程序文件。但是有时需要公用一个份数据库。这时就需要数据库能远程连接。

现在以mysql为例演示一下。

这里远程连接可以

1.允许固定客户端ip登陆。

select host,user,password from mysql;

mysql> select host,user,password from user;
+-----------+------+----------+
| host      | user | password |
+-----------+------+----------+
| localhost | root |          |
| linux     | root |          |
| localhost |      |          |
| linux     |      |          |
| localhost | pma  |          |
+-----------+------+----------+
5 rows in set (0.00 sec)

对root进行赋权限

A.grant select,update,insert,delete on *.* to root@192.168.0.110 identified by "";

这样root用户就可以在192.168.0.110机器上登陆了。

mysql> grant select,update,insert,delete on *.* to root@192.168.0.110 identified
 by "";
Query OK, 0 rows affected (0.00 sec)

mysql> select host,user,password from user;
+---------------+------+----------+
| host          | user | password |
+---------------+------+----------+
| localhost     | root |          |
| linux         | root |          |
| localhost     |      |          |
| linux         |      |          |
| localhost     | pma  |          |
| 192.168.0.110 | root |          |
+---------------+------+----------+
6 rows in set (0.00 sec)

  

B.grant all privileges on *.* to root@'%' identified by "";

这样root用户就可以在任何ip的客户端登陆,并且有all privileges。

mysql> grant all privileges on *.* to root@'%' identified by "";
Query OK, 0 rows affected (0.00 sec)

mysql> select host,user,password from mysql;
ERROR 1146 (42S02): Table 'mysql.mysql' doesn't exist
mysql> select host,user,password from user;
+---------------+------+----------+
| host          | user | password |
+---------------+------+----------+
| localhost     | root |          |
| linux         | root |          |
| localhost     |      |          |
| linux         |      |          |
| localhost     | pma  |          |
| 192.168.0.110 | root |          |
| %             | root |          |
+---------------+------+----------+
7 rows in set (0.00 sec)

  mysql> grant select,update,insert,delete on *.* to root@'%' identified by "";

Query OK, 0 rows affected (0.00 sec)

mysql> select host,user,password from user;
+---------------+------+----------+
| host          | user | password |
+---------------+------+----------+
| localhost     | root |          |
| linux         | root |          |
| localhost     |      |          |
| linux         |      |          |
| localhost     | pma  |          |
| 192.168.0.110 | root |          |
| %             | root |          |
+---------------+------+----------+
7 rows in set (0.00 sec)
mysql> flush privileges;

  

可以看出格式为 grant PRIVILEGES on DATEBASE.TABLE to USER@HOST identified by PASSWORD;

而且这条语句也可以增加用户。

posted @ 2013-07-25 09:59  simpman  阅读(389)  评论(0编辑  收藏  举报