Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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');
share|improve this answer
    
Thanks, What about apache configs? –  Yosef Mar 16 '11 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 '11 at 12:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.