2

MySQL Server is running on Dreamhost VPS and i am able to make connection with it through my Dev machine (Windows) and when i connect with with MySQL Server from my CentOS7 VM than i get following error:

PHP message: SQLSTATE[HY000] [2003] Can't connect to MySQL server on '*******' 

I have configured my MySQL Server to accept connection from all hosts (%) Not sure why i am able to connect through my Dev machine and not from CentOS 7 VM running on my Dev machine, I have not installed MySQL on my CentOS VM (Minimal) only PHP + nginx are installed.

Thanks -Shahram

MWiesner
  • 8,868
  • 11
  • 36
  • 70
shary
  • 178
  • 2
  • 12

2 Answers2

0

It sounds like your permissions are correctly setup in mysql for the user to connect from all hosts (%). This sounds more like a networking setup issue.

By default the mysql configuration file only allows connection from localhost. To enable connections beyond localhost you will need to edit this config file (usually found in /etc/mysql/my.cnf on Unix/OSX and "C:\Program Files\MySQL\" with filename my.ini)

Edit the line:

bind-address = 127.0.0.1

You can allow connections from any source by commenting out this line, changing it to:

# bind-address = 127.0.0.1

See also: How to allow remote connection to mysql

Community
  • 1
  • 1
eckymad
  • 1,032
  • 8
  • 6
  • Like i said i am able to make connection to my remove MySQL Server from my Dev machine, – shary Jan 03 '16 at 12:22
0

From my point of view your virtualization software does not allow you to go outside vm's private network.

Which virtualization sofware do you use (virtualbox, vmware )? Can you enable connection with telnet your_mysql_server_ip on port 3306?

Bowdzone
  • 3,827
  • 11
  • 39
  • 52
dodgers
  • 1
  • 2
  • Using Virtualbox and yes i have enabled the connection with my MYSQL Server – shary Jan 03 '16 at 12:26
  • Can you provide php connection line in your code ? does your CENTOS VM is configured with natted or brigded network ? – dodgers Jan 03 '16 at 12:31
  • try{ $db_info['db_options'] = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_PERSISTENT => true); $dsn = $db_info['db_type'] . ':dbname=' . $db_info['db_name'] . ';host=' . $db_info['db_host']; $this->connection = new PDO($dsn, $db_info['db_user'], $db_info['db_password'], $db_info['db_options']); }catch (Exception $ex) { error_log($ex->getMessage()) } – shary Jan 03 '16 at 12:36
  • i dont think so there is any issue in code, as same code is running on my Dev machine, Application Server – shary Jan 03 '16 at 12:38
  • do you use ip address or fqdn in $db_info['db_host'] ? are you sure this variable is filled – dodgers Jan 03 '16 at 12:38
  • i am using Server URL not IP, yes these variable get filled as i added the error_log(print_r($db_info, true)) in catch block and system is showing correct values, – shary Jan 03 '16 at 12:46
  • Does your vm can resolve the hostname or your db server ? nslookup hosname – dodgers Jan 03 '16 at 12:50
  • If you can resolve the hostname , i think that your problem come from the firewall on your VPS host. – dodgers Jan 03 '16 at 13:07
  • i am added the server IP to allowed connection list in iptables – shary Jan 03 '16 at 13:10
  • Do you see something coming in your mysql.log file ? add log=/tmp/mysql.log in [mysqld] section in file my.cnf then restart your mysql server. retry a connection and see what happening in /tmp/mysql.cnf. if you see your connection in logfile this means that your privileges is not well set. – dodgers Jan 03 '16 at 13:30