3

I want to establish a connection between my local machine and MySQL database server via Python.

Can someone tell me how to "bind-address with localhost"?

Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
Guru Prakash S
  • 413
  • 2
  • 5
  • 9
  • What are your settings now? What have you tried? – madfriend Jun 24 '12 at 09:23
  • Is it possible that you have a firewall problem? There's a similar problem posted http://stackoverflow.com/questions/5755819/lost-connection-to-mysql-server-at-reading-initial-communication-packet-syste – root Jun 24 '12 at 09:30

1 Answers1

6

Can someone tell me how to "bind-address with localhost"?

This is a MySQL configuration directive.

Edit the global my.ini file, in the [mysqld] section:

[mysqld]
# -- various other settings
port = 3306
bind-address = 127.0.0.1
# -- other settings

Save this file, and then restart your server.

Edit

If you want to connect to your local Windows instance of MySQL, simply use 127.0.0.1 as the server's address.

If you want to connect to your remote server, the one running Linux then it is a bit complicated:

  1. First, make sure MySQL is listening on the public IP of the Linux server. Change the line bind-address = and set it to the public IP of your server.

  2. Make sure port 3306 isn't blocked by any firewall.

  3. The user that you use to connect to the server needs to have rights to connect from a remote IP. By default, users are only given rights to connect from localhost - in other words they can only connect if the program is running on the same machine as the server itself.

To grant a user access from a remote IP, run this command from the mysql> shell when logged in with the MySQL root user:

GRANT ALL on somedb.* to someuser@8.8.8.8 identified by 'somepassword';

If you want to grant access to someuser from any remote IP:

GRANT ALL on somedb.* to someuser@% identified by 'somepassword';

After those steps, make sure to restart the MySQL server so it will read the changes in the configuration.

Community
  • 1
  • 1
Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284
  • thank you...! but can you please tell me where exactly I'm going to find this my.ini file....? I'm trying to connect from my local machine(Windows OS) to my server(linux os) and I have installed MySQL "community server " in my local machine. – Guru Prakash S Jun 24 '12 at 17:28
  • I have perfected in the 2nd and 3rd step.... but i am not able to locate the my.ini global file..? where should i look for it..? – Guru Prakash S Jun 25 '12 at 06:50
  • Should be somewhere in `/etc`. On debian systems it is `/etc/mysql/my.cnf` – Burhan Khalid Jun 25 '12 at 06:53
  • but i run on windows.. any idea..? – Guru Prakash S Jun 25 '12 at 07:11
  • If your server is on Windows, and your application is on Windows, then you don't need to do anything. Otherwise, run the [server configuration wizard](http://dev.mysql.com/doc/refman/5.0/en/mysql-config-wizard-starting.html) – Burhan Khalid Jun 25 '12 at 07:22