Home  >  Article  >  Database  >  关于MYSQL 远程登录的授权方法 命令

关于MYSQL 远程登录的授权方法 命令

WBOY
WBOYOriginal
2016-06-07 18:05:24939browse

默认是不允许远程连接的,因为有很大的安全隐患。需要手动增加可以远程访问数据库的用户

方法一、本地登入mysql,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,将"localhost"改为"%"

#mysql -u root -proot
mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;

方法二、直接授权(推荐)

从任何主机上使用root用户,密码:youpassword(你的root密码)连接到mysql服务器:

# mysql -u root -proot
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'youpassword' WITH GRANT OPTION;
  允许地址202.11.10.253上用root用户,密码dboomysql来连接mysql的所有数据库,付给select,insert,update,delete权限。

# mysql -u root -proot
grant select,insert,update,delete on *.* to root@"202.11.10.253" Identified by "dboomysql";
  允许地址202.11.10.253上用root用户,密码dboomysql来连接mysql的所有数据库,付给所有权限。

# mysql -u root -proot

grant all on *.* to root@"202.11.10.253" Identified by "dboomysql"

操作完后切记执行以下命令刷新权限

FLUSH PRIVILEGES
Statement:
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