Home  >  Article  >  Database  >  mysql的局域网连接

mysql的局域网连接

WBOY
WBOYOriginal
2016-06-07 15:39:381355browse

在Ubuntu上安装好mysql服务器后,需要在局域网里通过jdbc进行访问,开始怎么都不成功。 后来查找了一些资料,做了如下修改。 1.默认情况下, 使用MySQL只能通过本机Socket连接,需要修改my.cnf(在/etc/mysql下), 注释 #bind-address = 127.0.0.1 2.授权从任何

在Ubuntu上安装好mysql服务器后,需要在局域网里通过jdbc进行访问,开始怎么都不成功。

后来查找了一些资料,做了如下修改。

1.默认情况下,使用MySQL只能通过本机Socket连接,需要修改my.cnf(在/etc/mysql下),注释

#bind-address   = 127.0.0.1
2.授权从任何主机连接到mysql服务器

GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;   
flush privileges;
然后重启mysql服务器

sudo service mysql restart


可以通过:mysql -h192.168.1.102 -uroot -p 进行测试

在java中连接的url为 jdbc:mysql:ip_addr:3306/db_name.





Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn