博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

通过HeidiSQL连接MySQL数据库报错:
 SQL Error (1130): Host '192.168.1.126' is not allowed to connect to this MySQL server
说明所连接的用户帐号没有远程连接的权限,只能在本机(localhost)登录。
需更改 mysql 数据库里的 user表里的 host项把localhost改称%
首先按下面的步骤登录Mysql服务器
登录mysql需要切换到dos下的mysql的bin目录,进行如下操作:
mysql>use mysql;

mysql>update user set host = '%'  where user ='root';
MariaDB [mysql]> update user set host = '%' where host = 'localhost';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0  Changed: 0  Warnings: 0

mysql>flush privileges;
mysql> select host, user from user;
mysql>quit
OK。远程连接成功!

MyDSM> mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 17
Server version: 5.5.47-MariaDB Source distribution

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

MariaDB [(none)]> use mysql;
Database changed

MariaDB [mysql]> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| event                     |
| func                      |
| general_log               |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| host                      |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| proxies_priv              |
| servers                   |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
24 rows in set (0.00 sec)

MariaDB [mysql]> update user set host = '%' where host = 'localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> select host, user from user;
+-----------+------+
| host      | user |
+-----------+------+
| %         |      |
| %         | root |
| 127.0.0.1 | root |
| ::1       | root |
| mydsm     |      |
| mydsm     | root |
+-----------+------+
6 rows in set (0.00 sec)

MariaDB [mysql]> quit
Bye