0

I am trying to connect to VPS mysql database from my PC. I use sqlalchemy framework, but I need establish SSH tunnel before connection.

Usual way, when web app run on VPS:

create_engine('mysql://user:pswd@localhost/dbname')

How can I connect to this database from another PC. Assume there are connections credentials: IP, username, password

  • What happens when you replace `localhost` with the IP address of the database server? – Selcuk Feb 12 '15 at 12:16
  • When I pass IP with SSH port 22: sqlalchemy.exc.OperationalError: (OperationalError) (2013, "Lost connection to MySQL server at 'reading initial communication packet', system error: 0") None None – Šimon Kostolný Feb 12 '15 at 12:21
  • And with mysql port 3306: sqlalchemy.exc.OperationalError: (OperationalError) (2003, "Can't connect to MySQL server on 'xxx.xxx.xxx.xxx' (111)") None None – Šimon Kostolný Feb 12 '15 at 12:22

1 Answers1

1

Your MySQL server is listening to local connections only. To make it listen to outside connections:

  1. Edit the /etc/mysl/my.cnf file
  2. Comment out the line bind-address = 127.0.0.1
  3. Restart mysqld
Selcuk
  • 57,004
  • 12
  • 102
  • 110
  • It was uncommented. I think that I have to connect to VPS through SSH tunnel but I do not know how. – Šimon Kostolný Feb 12 '15 at 12:33
  • You should **comment** it if it is uncommented. – Selcuk Feb 12 '15 at 12:36
  • after 'create_engine('mysql://mysql_username:mysql_pswd@IP:3306/db_name')' : **sqlalchemy.exc.OperationalError: (OperationalError) (1130, "Host 'bband-dyn233.178-41-4.t-com.sk' is not allowed to connect to this MySQL server") None None** – Šimon Kostolný Feb 12 '15 at 12:45
  • This is another (privilege) problem. See: http://stackoverflow.com/questions/1559955/host-xxx-xx-xxx-xxx-is-not-allowed-to-connect-to-this-mysql-server – Selcuk Feb 12 '15 at 12:46