ERROR 1130 (HY000): Host 'Lenovo-PC' is not allowed to connect to this MySQL servermysql
MySQL受權容許鏈接之ERROR 1130 (HY000)sql
C:\Users\Lenovo>mysql -h 10.255.9.79 -u root -p034039 Warning: Using a password on the command line interface can be insecure. ERROR 1130 (HY000): Host 'Lenovo-PC' is not allowed to connect to this MySQL server C:\Users\Lenovo>mysql -h localhost -u root -p034039 Warning: Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 54 Server version: 5.6.21 MySQL Community Server (GPL) Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
你們從上面這段信息中能夠看出當使用h參數爲本機的ip地址時,mysql不容許該客戶端鏈接,這是爲何呢?shell
看下面這段sql查詢:數據庫
mysql> use mysql Database changed mysql> select user,host from user; +------+-----------+ | user | host | +------+-----------+ | root | 127.0.0.1 | | root | ::1 | | | localhost | | root | localhost | +------+-----------+ 4 rows in set (0.00 sec)
root用戶只容許在127.0.0.1和localhost上進行鏈接,而不容許使用本機在局域網中的ip進行鏈接。。。this
這樣就明白爲何不容許鏈接的緣由了。spa
下面就要給root用戶相應的登錄權限code
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'10.255.9.79' IDENTIFIED BY '034039' WITH GRANT OPTION; Query OK, 0 rows affected (0.23 sec) mysql> select user,host from user ; +------+-------------+ | user | host | +------+-------------+ | root | 10.255.9.79 | | root | 127.0.0.1 | | root | ::1 | | | localhost | | root | localhost | +------+-------------+ 5 rows in set (0.00 sec) mysql>
經過這條受權語句,server
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'10.255.9.79' IDENTIFIED BY '034039' WITH GRANT OPTION;
容許地址10.255.9.79上用root用戶,密碼034039來鏈接mysql的全部數據庫,付給select,insert,update,delete權限。ip
最後刷新一下權限:input
mysql> flush privileges; Query OK, 0 rows affected (0.68 sec)
OK,這樣就完成了受權。
C:\Users\Lenovo>mysql -h 10.255.9.79 -u root -p034039 Warning: Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 55 Server version: 5.6.21 MySQL Community Server (GPL) Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
=======END=======