UPDATE mysql.user SET host = '10.0.0.%' WHERE host = 'internalfoo' AND user != 'root';
UPDATE mysql.db SET host = '10.0.0.%' WHERE host = 'internalfoo' AND user != 'root';
FLUSH PRIVILEGES;
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)
我需要这些用户移动到“ localhost”:
UPDATE mysql.user SET host = 'localhost' WHERE user = 'foo';
UPDATE mysql.user SET host = 'localhost' WHERE user = 'bar';
再次运行 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 | localhost |
| bar | localhost |
+-------+-------------+
4 rows in set (0.00 sec)
然后我又可以正常工作了,希望这对某些人有帮助。
$ 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)]>
最可靠的方法似乎是为老用户运行 SHOW GRANTS,找到/替换您想要更改的关于用户名和/或主机的内容,然后运行它们,最后为老用户运行 DROP USER。不要忘记运行 FLUSH PRIVILEGES(最好在添加新用户的授权之后运行它,测试新用户,然后删除旧用户并再次刷新以获得更好的效果)。
> SHOW GRANTS FOR 'olduser'@'oldhost';
+-----------------------------------------------------------------------------------+
| Grants for olduser@oldhost |
+-----------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'olduser'@'oldhost' IDENTIFIED BY PASSWORD '*PASSHASH' |
| GRANT SELECT ON `db`.* TO 'olduser'@'oldhost' |
+-----------------------------------------------------------------------------------+
2 rows in set (0.000 sec)
> GRANT USAGE ON *.* TO 'newuser'@'newhost' IDENTIFIED BY PASSWORD '*SAME_PASSHASH';
Query OK, 0 rows affected (0.006 sec)
> GRANT SELECT ON `db`.* TO 'newuser'@'newhost';
Query OK, 0 rows affected (0.007 sec)
> DROP USER 'olduser'@'oldhost';
Query OK, 0 rows affected (0.016 sec)