这是一个新的MySQL Server安装。我创建了root密码作为设置的一部分(在Centos 6.4上)。
当我通过终端连接到服务器时,我可以使用我的root密码连接到MySQL并发出命令。
选择current_user;
给了我:
+----------------+
| current_user |
+----------------+
| root@localhost |
+----------------+
如果我这样做:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'xxxxxx' WITH GRANT OPTION
我明白了:
Query OK, 0 rows affected (0.00 sec)
但是当我这样做时:
SHOW GRANTS;
这是我得到的:
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*fdfgdgdggfggfgfg' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------------------------------------------+
除了root @ localhost之外,我还不应该看到root @%的另一行吗?
我遇到的真正问题是我无法从localhost外部连接到MySQL(例如,我使用终端会话登录),如果MySQL服务器是没有给予root通用访问权限(root @%),那就解释了这个问题。当我尝试使用PHP(来自我的本地MAC)连接时,以下是返回的MySQLi对象:
mysqli Object
(
[affected_rows] =>
[client_info] =>
[client_version] => 50008
[connect_errno] => 2002
[connect_error] => Connection refused
[errno] =>
[error] =>
[field_count] =>
[host_info] =>
[info] =>
[insert_id] =>
[server_info] =>
[server_version] =>
[stat] =>
[sqlstate] =>
[protocol_version] =>
[thread_id] =>
[warning_count] =>
)