0

What should I do for change my connection from other network computer mysql to my computer mysql?

My computer run web application with his apache local server and mysql that located in other computer in our network. I want to connect to my local mysql instead.

(I have ubuntu 10.04 + lamp)

Thanks, Yosef

1 Answer 1

1

You've two machines:

  • A: the machine on which Apache resides. IP address 10.0.0.2
  • M: the machine with the MySQL database. IP address 10.0.0.3

In a default MySQL installation, MySQL listens on all interfaces and thus, other machines can reach it on it's public (network) IP address on port 3306 (default port or MySQL).

To allow A to connect with M, a MySQL account should be present on M allowing [email protected] to connect with MySQL (user = accountname). In your webapp on A, use hostname 10.0.0.3, username accountname and a password as set for [email protected].

If there is a firewall on M, be sure to allow incoming connections to TCP port 3306 on M.

Assuming your webapp uses PHP as language, replace something like:

$oCon = new MySQLi('localhost', 'accountname', 'password', 'database');

by:

$oCon = new MySQLi('10.0.0.3', 'accountname', 'password', 'database');
2
  • Thanks, What about apache configs?
    – Ben
    Mar 16, 2011 at 12:43
  • There is no need to mess with the Apache configuration, unless you do not specify the host while connecting from PHP. In that case, you need to set the default hostname (mysqli.default_hostname for MySQLi; mysql.default_hostname for MySQL) to 10.0.0.3.
    – Lekensteyn
    Mar 16, 2011 at 12:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .