MySQL远程访问权限,允许远程连接的开启
1、登陆mysql
数据库
mysql
-u root -p
查看user表 www.2cto.com
mysql> use mysql;
Database changed
mysql> select host,user,password from user;
+--------------+------+-------------------------------------------+
| host | user | password |
+--------------+------+-------------------------------------------+
| localhost | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
| 192.168.1.1 | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
+--------------+------+-------------------------------------------+
2 rows in set (0.00 sec)
可以看到在user表中已创建的root用户。host字段表示登录的主机,其值可以用IP,也可用主机名,
(1)有时想用本地IP登录,那么可以将以上的Host值改为自己的Ip即可。
2、实现远程连接(授权法)
将host字段的值改为%就表示在任何客户端机器上能以root用户登录到mysql服务器,建议在开发时设为%。
update user set host = ’%’ where user = ’root’;
将权限改为ALL PRIVILEGES
mysql> use mysql;
Database changed
mysql> grant all privileges on *.* to root@'%' identified by "root";
Query OK, 0 rows affected (0.00 sec) www.2cto.com
mysql> select host,user,password from user;
+--------------+------+-------------------------------------------+
| host | user | password |
+--------------+------+-------------------------------------------+
| localhost | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
| 192.168.1.1 | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
| % | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
+--------------+------+-------------------------------------------+
3 rows in set (0.00 sec)
这样机器就可以以用户名root密码root远程访问该机器上的MySql.
3、实现远程连接(改表法)
use mysql;
update user set host = '%' where user = 'root';
这样在远端就可以通过root用户访问Mysql.
如果还不行 修改my.cnf配置文件 跳过dns解析
/*
[mysqld]
skip-name-resolve
*/
[client]
port=3306
socket=/var/lib/mysql/mysql.sock
default-character-set=utf8
如果还不行 修改my.cnf配置文件 跳过dns解析
/*
[mysqld]
skip-name-resolve
*/
[client]
port=3306
socket=/var/lib/mysql/mysql.sock
default-character-set=utf8
[mysqld]
skip-name-resolve
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
skip-name-resolve
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
# Disabling symbolic-links is recommended to prevent assorted security risks;
# to do so, uncomment this line:
# symbolic-links=0
default-character-set=utf8
init_connect='SET NAMES utf8'
# to do so, uncomment this line:
# symbolic-links=0
default-character-set=utf8
init_connect='SET NAMES utf8'
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid