Eug*_*ene 1 java mysql jdbc ubuntu-server
我在本地虚拟机上运行ubuntu服务器,我需要连接到那里的mysql数据库.数据库已到位并且jdbc驱动程序也是如此.唯一的问题是,目前只有我的连接方式可以是类似的http://local/phpmyadmin/index.php?db=sandbox,不能在jdbc连接字符串中使用.
希望,有人可以建议解决方案.
String url = "jdbc:mysql://localhost:3306/mysql";
Connection con = DriverManager.getConnection(url,"username", "pwd");
Run Code Online (Sandbox Code Playgroud)
替换localhost为VM的IP.您必须使用NAT之外的其他东西在VM中进行联网(例如,仅限主机,内部或桥接,假设VirtualBox).
您可能必须配置您的Ubuntu防火墙以通过连接.
此外,您必须设置mysql以接受来自外部的连接.在文件中/etc/mysql/my.cnf编辑绑定地址到你的ip:
bind-address = your-vms-ip
Run Code Online (Sandbox Code Playgroud)