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
  • 相关阅读:
    elastic
    Leetcode题库 第十行
    Leetcode题库-实现strStr()
    Redis持久化
    Redis的数据结构及应用场景
    Redis缓存的淘汰策略
    Redis缓存常见问题
    Redis面试题1
    消息队列的原理及选型
    【转载】java高并发/mysql/mybatis/spring博客
  • 原文地址:https://www.cnblogs.com/simpman/p/3213722.html
Copyright © 2011-2022 走看看