简体   繁体   中英

How can I connect to a mysql db from a different server?

I have, let's say, a root website with mysql db on a remote server.

I want to connect to that particular database (to make queries), from many other little websites (with lower priviledges).

Can this be done?

Language: jsp, java, php

Any particular problem? Just specify server address instead of 'localhost' in connection string.
You can also create dedicated user with minimal privileges for that.

Yes it can be done, MySQL allows connections from remote hosts (assuming MySQL is configured to allow network connections and assuming the remote hosts are granted). In case of problem, the section 5.4.7. Causes of Access-Denied Errors lists most common problems and solutions.

The default configuration often contains a variable

 skip-networking

which you need to comment-out in order to have networking enabled.

In addition to the answers from Nikita Rybak andPascal Thivent, I'd like to note that most hosting providers don't allow queries from locations other than localhost.

I don't know how much access you have to the server configuration, but I would have saved myself a headache a while back when I first started experimenting with connections across domains/servers.

If the MySQL server is under your control, it's not difficult; you can find the procedure here . If it's not, the only thing you can do is beg the admin to do it, otherwise it's impossible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM