bitscn.com
安装好mysql后允许远程连接http://blog.sina.com.cn/s/blog_3eba8f1c0100tsox.html
http://blog.csdn.net/zxyvb/article/details/2462514
http://www.bitscn.com/article/31902.htm
在虚拟机安装好mysql后,看一下虚拟机mysql服务有没有开,侦听的端口是否是3306
1 netstat -anp|more
打开防火墙的端口3306
#/sbin/iptables -i input -p tcp --dport 3306 -j accept
然后保存:
#/etc/rc.d/init.d/iptables save
查看打开的端口:
# /etc/init.d/iptables status
-------------------------------------------------------
补充说明:
#关闭防火墙
/etc/init.d/iptables stop
service iptables stop # 停止服务
#查看防火墙信息
/etc/init.d/iptables status
#开放端口:8080
/sbin/iptables -i input -p tcp --dport 8080 -j accept
#重启防火墙以便改动生效:(或者直接重启系统)
/etc/init.d/iptables restart
#将更改进行保存
/etc/rc.d/init.d/iptables save
另外直接在/etc/sysconfig/iptables中增加一行:
-a rh-firewall-1-input -m state –state new -m tcp -p tcp –dport 8080 -j accept
#永久关闭防火墙
chkconfig –level 35 iptables off #此方法源自网络,未实验,安全考虑拒绝使用此方法
error 1130: host '192.168.1.3' is not allowed to connect to this mysql .
当使用mysql帐号远程登陆的时候,出现类似如下错误:
error 1130: host '192.168.1.3' is not allowed to connect to this mysql
解决办法:
1. 改表法(可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 mysql 数据库里的 user 表里的 host 项,从localhost改称%)
c:/mysql/mysql server 5.1>mysql -u root -p
输入相应密码
mysql>use mysql;
mysql>show tables; (确认一下表user是否存在)
mysql>update user set host='%' where user='root';
mysql>quit
退出mysql
c:/mysql/mysql server 5.1>net stop mysql
c:/mysql/mysql server 5.1>net start mysql
现在远程连接这部mysql服务器就行了
c:/mysql/mysql server 5.1>mysql -h 192.168.1.3 -u root -p
2. 授权法
例如,你想myuser使用mypassword从任何主机连接到mysql服务器的话。
grant all privileges on *.* to 'myuser'@'%' identified by 'mypassword' with grant option;
如果你想允许用户myuser从ip为192.168.1.3的主机连接到mysql服务器,并使用mypassword作为密码
grant all privileges on *.* to 'myuser'@'192.168.1.3' identified by 'mypassword' with grant option;
远程连接mysql 授权方法详解
今在服务器上 有mysql 数据库,远程访问,不想公布root账户,所以,创建了demo账户,允许demo账户在任何地方都能访问mysql数据库中shandong库。
方案一:
在安装mysql的机器上运行:
1: 创建user用户
复制代码 代码如下:
create user demo identified by “123456”
2、
复制代码 代码如下:
mysql>grant all privileges on shandong.* to 'demo'@'%'with grant option
//赋予任何主机访问数据的权限,也可以如下操作
grant all privileges on shandong.* to 'demo'@'%'identified by '123456' with grant option;
3、
复制代码 代码如下:
mysql>flush privileges
//修改生效
4、
复制代码 代码如下:
mysql>exit
//退出mysql服务器,这样就可以在其它任何的主机上以demo身份登录
引用
另外,当用客户端连接 mysql 时,发现无法连接,看来需要对用户进行重新授权。操作如下:
[root@cicro108 mysql]# bin/mysql -uroot -p -h 127.0.0.1 -a cws3
enter password:
welcome to the mysql monitor. commands end with or /g.
your mysql connection id is 1863 to server version: 4.1.20-standard
type 'help;' or '/h' for help. type '/c' to clear the buffer.
mysql> grant all privileges on *.* to root@% identified by mysql ;
query ok, 0 rows affected (0.17 sec)
发现这样更改权限以后,远程仍然不能连接,但是用下面的操作就可以了。
mysql> grant all privileges on *.* to root@% identified by mysql with grant option;
query ok, 0 rows affected (0.17 sec)
此刻, root 可以被远程连接,当然这里建立其他非 root 用户也可以远程连接。
方案二:
mysql 1130错误解决方法:
通过mysql-front或mysql administrator连接mysql的时候发生的这个错误
error 1130: host ***.***.***.*** is not allowed to connect to this mysql server
说明所连接的用户帐号没有远程连接的权限,只能在本机(localhost)登录。
需更改 mysql 数据库里的 user表里的 host项
把localhost改称%
具体步骤:登陆到mysql
首先 use mysql;
按照别人提供的方式update的时候,出现错误。
mysql> update user set host='%' where user = 'root';
error 1062 (23000): duplicate entry '%-root' for key 'primary'
然后查看了下数据库的host信息如下:
mysql> select host from user where user = 'root';
+-----------------------+
| host |
+-----------------------+
| % |
| 127.0.0.1 |
| localhost.localdomain |
+-----------------------+
3 rows in set (0.00 sec)
host已经有了%这个值,所以直接运行命令:
复制代码 代码如下:
mysql>flush privileges;
再用mysql administrator连接...成功!!
bitscn.com