之前的设置:
通过命令行登录管理MySQL服务器(提示输入密码时直接回车):
mysql> /usr/local/webserver/mysql/bin/mysql -u root -p -S /tmp/mysql.sock
mysql> GRANT ALL
PRIVILEGES ON *.* TO ‘admin‘@‘localhost‘ IDENTIFIED BY
‘12345678‘;
mysql> GRANT ALL
PRIVILEGES ON *.* TO ‘admin‘@‘127.0.0.1‘ IDENTIFIED BY
‘12345678‘;
(1)可以把127.0.0.1改成你希望访问的IP
(2)‘%‘怎表示任何IP都可以访问。
1、修改表,登录mysql数据库,切换到mysql数据库,使用sql语句查看
2、授权用户,你想root使用密码从任何主机连接到mysql服务器
GRANT ALL PRIVILEGES ON *.*
TO ‘root‘@‘%‘ IDENTIFIED BY ‘admin123‘ WITH
GRANT OPTION;flush privileges;
如果你想允许用户root从ip为192.168.12.16的主机连接到mysql服务器
GRANT ALL PRIVILEGES ON *.*
TO ‘root‘@‘192.168.1.16‘ IDENTIFIED BY
‘123456‘ WITH GRANT OPTION;
[root@localhost bin]# ./mysql -uroot -p
Enter
password:
Welcome to the MySQL monitor. Commands end with ; or
\g.
Your MySQL connection id is 9277
Server version: 5.5.3-m3-log Source
distribution
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
mysql> GRANT ALL PRIVILEGES ON *.* TO‘admin‘@‘%‘ IDENTIFIED
BY ‘Xinying_2010‘;
ERROR 2006 (HY000): MySQL server has gone
away
No connection. Trying to reconnect...
Connection
id: 9324
Current database: *** NONE ***
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00
sec)
注意:最后一句很重要,目的是使修改生效.如果没有写,则还是不能进行远程连接.
现在就可以使用mysql的客户端软件去连接你的数据库了
我使用的是Navicat for MySQL