ubuntu下mysql远程连接问题

来源:互联网 发布:linux怎么装 编辑:程序博客网 时间:2024/04/27 16:22

dbcp连接mysql ip地址127.0.0.1连接可以换成本地真正ip报

org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory

网上说可能连接关闭了需要重新连接

在connection中的url参数最后加入?autoReconnect=true

结果错误

nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Could not create connection to database server. Attempted reconnect 3 times. Giving up.)

还是连不上

郁闷中

然后利用mysql -uroot -p -h 真正IP连mysql报错

mysql error number 2003   

Can't connect to MySQL server xxx.xxx.xxx.xxx (10061)

噢终于明白了,远程端口mysql不认,真TMD

原来在ubuntu 9.04中默认安装了mysql,默认只能本地访问,如果远程访问需要另外设置

解决办法:

授权允许远程机器以指定用户访问

GRANT all privileges ON *.* to root@ IDENTIFIED BY "root";

重启mysql

/etc/init.d/mysql restart

重新登录

mysql -uroot -p -h ip

还是不行

修改mysql配置文件

vi /etc/mysql/my.cnf

bind-address = 127.0.0.1注释掉

重启mysql

成功

原创粉丝点击