如何设置mysql远程访问

1.查看远程主机mysql服务状态

1 [root@localhost ~]# service mysqld status
2 mysqld is stopped

2.启动远程机mysql服务

如mysql服务未启动, 则先启动mysql服务

[root@localhost ~]# /etc/init.d/mysqld start
Starting MySQL:                                            [  OK  ]

3.进入mysql

[root@localhost ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.0.45 Source distribution

Type 'help;' or 'h' for help. Type 'c' to clear the buffer.

mysql>

4.选择mysql库名

1 mysql> use mysql;
2 Reading table information for completion of table and column names
3 You can turn off this feature to get a quicker startup with -A
4 
5 Database changed
6 mysql> 

5.将mysql库中, root用户的host由localhost改为%

mysql> UPDATE user SET Host='%' WHERE User='root';

6.打开防火墙的3306mysql默认端口, 可参照http://www.cnblogs.com/leaf1117/p/3461952.html              

         
7.重启服务

原文地址:https://www.cnblogs.com/leaf1117/p/3461958.html