Home > Database > Mysql Tutorial > 设置mysql远程连接root权限_MySQL

设置mysql远程连接root权限_MySQL

WBOY
Release: 2016-06-01 13:45:30
Original
1027 people have browsed it

bitsCN.com

在远程连接mysql的时候应该都碰到过,root用户无法远程连接mysql,只可以本地连,对外拒绝连接。

需要建立一个允许远程登录的数据库帐户,这样才可以进行在远程操作数据库。

方法如下:

默认情况下MYSQL数据库的系统数据库mysql系统表user内用户权限只提供localhost本机登陆;

需要更改权限才能实现远程连接MYSQL数据库。

可以通过以下方式来确认:

root#mysql -h localhost -uroot -p

Enter password: ******

Welcome to the MySQL monitor.   Commands end with ; or /g.

Your MySQL connection id is 4 to server version: 4.0.20a-debug

Type ‘help;’ or ‘/h’ for help. Type ‘/c’ to clear the buffer.

mysql> use mysql; (此DB存放MySQL的各种配置信息)

Database changed

mysql> select host,user from user; (查看用户的权限情况)

mysql> select host, user, password from user;
+-----------+------+-------------------------------------------+
| host       | user | password                                   |
+-----------+------+-------------------------------------------+
| localhost | root | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 |
| 127.0.0.1 | root | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 |
| localhost |       |                                            |
+-----------+------+-------------------------------------------+
4 rows in set (0.01 sec)

由此可以看出,只能以localhost的主机方式访问。
解决方法:
mysql> Grant all privileges on *.* to 'root'@'%' identified by 'kdm001' with grant option;
(%表示是所有的外部机器,如果指定某一台机,就将%改为相应的机器名;‘root’则是指要使用的用户名,)
mysql> flush privileges;    (运行此句才生效,或者重启MySQL)
Query OK, 0 rows affected (0.03 sec)

再次查看。。

mysql> select host, user, password from user;
+-----------+------+-------------------------------------------+
| host       | user | password                                   |
+-----------+------+-------------------------------------------+
| localhost | root | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 |
| 127.0.0.1 | root | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 |
| localhost |       |                                            |
| %          | root | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 |
+-----------+------+-------------------------------------------+
4 rows in set (0.01 sec)

可以看出已经添加了一个新的用户
 
检查mysqld监听模式是不是设为只监听localhost了,
 
用netstat看看,如果是的话。找到mysql的配置文件my.cnf,把bind address修改这台机器的真实IP就可以了
 
或者直接把bind address这一项注释掉也行。需要重启才能生效。

退出,试试效果....

现在可以成功登录了..

 

本文出自“jie的博客”

bitsCN.com
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template