zoukankan      html  css  js  c++  java
  • 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;

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

    如果感觉不错,请 一个!
    by simpman
  • 相关阅读:
    CodeForces 408E Curious Array(组合数学+差分)
    CodeForces 519E A and B and Lecture Rooms(倍增)
    洛谷 4051 [JSOI2007]字符加密(后缀数组)
    哇,两门学考都是A(〃'▽'〃)
    BZOJ 1977 严格次小生成树
    XJOI 3606 最大子矩形面积/LightOJ 1083 Histogram(单调栈/笛卡尔树)
    XJOI 3629 非严格次小生成树(pqq的礼物)
    XJOI 3363 树4/ Codeforces 739B Alyona and a tree(树上差分+路径倍增)
    [转载]别让用户发呆—设计中的防呆策略
    Linux下的链接文件
  • 原文地址:https://www.cnblogs.com/simpman/p/3213722.html
Copyright © 2011-2022 走看看