Home > Database > Mysql Tutorial > body text

如何打开MySQL中root账户的远程登录

WBOY
Release: 2016-06-07 15:27:19
Original
1221 people have browsed it

基于安全考虑root账户一般只能本地访问,但是在开发过程中可能需要打开root的远程访问权限。下面是基本的步骤: 1、登录到mysql中,为root进行远程访问的授权,执行下面的命令: mysql GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root"; mysql

基于安全考虑root账户一般只能本地访问,但是在开发过程中可能需要打开root的远程访问权限。下面是基本的步骤:

1、登录到mysql中,为root进行远程访问的授权,执行下面的命令:

 

mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root";

mysql> flush privileges;

 

第一句中"%"表示任何主机都可以远程登录到该服务器上访问。如果要限制只有某台机器可以访问,将其换成相应的IP即可,如:

GRANT ALL PRIVILEGES ON *.* TO root@"172.168.193.25" IDENTIFIED BY "root";

第二句表示从mysql数据库的grant表中重新加载权限数据。因为MySQL把权限都放在了cache中,所以在做完更改后需要重新加载。

 

2、修改/etc/mysql/my.cnf,需要root用户权限。找到文件中的:

 

 

将其注释掉,保存。

 

3、重新启动MySQL服务器。执行下面的几条命令即可:

# /usr/bin/mysqladmin -u root -p shutdown

# /usr/bin/mysqld_safe &

 

如果mysqladmin和mysql_safe不在/usr/bin目录中,可以通过whereis命令查找,例如:

# whereis mysqladmin
mysqladmin: /usr/bin/mysqladmin /usr/share/man/man1/mysqladmin.1.gz

 

执行完上面的三步后,就可以通过远程机器连接了数据库了。

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!