Home > Database > Mysql Tutorial > body text

mysql的局域网连接

WBOY
Release: 2016-06-07 15:39:38
Original
1354 people have browsed it

在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
Copy after login
2.授权从任何主机连接到mysql服务器

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

sudo service mysql restart


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

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





source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!