Java phpMyAdmin 数据库的连接字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4233365/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
connection string for phpMyAdmin database
提问by SLA
If I have a mysql database on my own pc, I would use the following cnxn string to connect it to my java program :
如果我自己的电脑上有一个 mysql 数据库,我会使用以下 cnxn 字符串将它连接到我的 java 程序:
String url = "jdbc:mysql://localhost:port/dbname";
String url = "jdbc:mysql://localhost:port/dbname";
But if my database is made over phpMyAdmin, what would be the connection string ? one other note, the phpmyadmin database is not on my local pc now, it is on another one but both pc are in the same network.
但是如果我的数据库是通过 phpMyAdmin 创建的,那么连接字符串是什么?另请注意,phpmyadmin 数据库现在不在我的本地电脑上,它在另一台电脑上,但两台电脑都在同一网络中。
Thanks for any help ..
谢谢你的帮助 ..
采纳答案by AbdullahC
Replace localhost with the IP of the machine that hosts your database:
将 localhost 替换为托管数据库的机器的 IP:
String url = "jdbc:mysql://<ip_goes_here>:port/dbname";
As Rutesh mentions, this may or may not be the same machine on which phpMyAdmin runs.
正如 Rutesh 所提到的,这可能是也可能不是运行 phpMyAdmin 的同一台机器。
回答by Rutesh Makhijani
phpMyadmin is administration web application developed on PHP platform. phpMyadmin connects to MySQL database that might be on other machine.
phpMyadmin 是在 PHP 平台上开发的管理 Web 应用程序。phpMyadmin 连接到可能在其他机器上的 MySQL 数据库。
you need to check config.inc.php file of phpMyadmin to check the host and port of mysql database.
你需要检查phpMyadmin的config.inc.php文件来检查mysql数据库的主机和端口。
Once you get the IP and port of the mysql database you can connect using connect string like
获得 mysql 数据库的 IP 和端口后,您可以使用连接字符串进行连接,例如
jdbc:mysql://<ipaddress>:<port>/<database_created_through_phpMyAdmin>