Re-assign host access permission to MySQL user

前端 未结 6 2320
情歌与酒
情歌与酒 2020-12-12 14:03

I have several thousand MySQL users all set to allow access from a specific host. The problem is that now I\'m going to have two machines (more in the future) which will nee

6条回答
  •  猫巷女王i
    2020-12-12 14:50

    Similar issue where I was getting permissions failed. On my setup, I SSH in only. So What I did to correct the issue was

    sudo MySQL
    SELECT User, Host FROM mysql.user WHERE Host <> '%';
    MariaDB [(none)]> SELECT User, Host FROM mysql.user WHERE Host <> '%';
    +-------+-------------+
    | User  | Host        |
    +-------+-------------+
    | root  | 169.254.0.% |
    | foo   | 192.168.0.% |
    | bar   | 192.168.0.% |
    +-------+-------------+
    4 rows in set (0.00 sec)
    

    I need these users moved to 'localhost'. So I issued the following:

    UPDATE mysql.user SET host = 'localhost' WHERE user = 'foo';
    UPDATE mysql.user SET host = 'localhost' WHERE user = 'bar';
    

    Run SELECT User, Host FROM mysql.user WHERE Host <> '%'; again and we see:

    MariaDB [(none)]> SELECT User, Host FROM mysql.user WHERE Host <> '%';
    +-------+-------------+
    | User  | Host        |
    +-------+-------------+
    | root  | 169.254.0.% |
    | foo   | localhost   |
    | bar   | localhost   |
    +-------+-------------+
    4 rows in set (0.00 sec)
    

    And then I was able to work normally again. Hope that helps someone.

    $ mysql -u foo -p
    Enter password:
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 74
    Server version: 10.1.23-MariaDB-9+deb9u1 Raspbian 9.0
    
    Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    MariaDB [(none)]>
    

提交回复
热议问题