0

I have executed both commands via SSH with no error and than when I try to connect to the MySQL server via SSH tunnel I get no results even if I do a simple query like select * from table.

I get no errors when I access the php script in live site.

I get this error: mysqli::mysqli(): (HY000/2002): Operation timed out when I access the php script hosted locally.

Both of them connect to the remote MySQL server of course. I have Apache and MySQL installed locally if that changes something.

Everything works fine when I connect via MySQL workbench.

I have also commented this line in my.cnf: #bind-address = 127.0.0.1

ssh -fNg -L 3307:127.0.0.1:3306 root@server_ip

mysql -h 127.0.0.1 -P 3307 -u root -p database_name

//php

$mysqli = new mysqli("127.0.0.1:3307", "root", "root", "database_name"); 

1 Answer 1

0
  1. mysqli constructor accepts 5th optional argumen specifying port. You should use

    $mysqli = new mysqli("127.0.0.1", "root", "root", "database_name", "3307"); 

instead.

  1. Did you verify you can connect to the port from the other host? Mysql is usually using unix domain socket instead of port (which you can forward too).

    ssh -fNg -L /var/run/mysqld/mysqld.sock:/var/run/mysqld/mysqld.sock root@server_ip 
1
  • I get this error when I run the second command. Bad local forwarding specification '/var/run/mysqld/mysqld.sock:/var/run/mysqld/mysqld.sock' Commented May 23, 2016 at 13:39

You must log in to answer this question.