如何连接远程mysql数据库

时间:2013-02-27 17:35:04

标签: php mysql linux remote-access mysql-error-2003

我查看了所有相关的问题和答案,但仍然无法连接到远程mysql数据库。

到目前为止我所做的是......

1

CREATE USER 'root'@'192.168.1.100' IDENTIFIED BY  '***';
GRANT ALL PRIVILEGES ON * . * TO  'root'@'192.168.1.100' IDENTIFIED BY  '***' WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;

2

my.cnf file in server (which is in /etc/my.cnf path let me if it is not correct)
[mysqld]
innodb_file_per_table=1
#bind-address = 127.0.0.1
#skip-networking

以下是我项目的database.yml。

all:
  doctrine:
    class: sfDoctrineDatabase
    param:
      dsn:      mysql:host=[ip of remote server];dbname=dev_db
      username: user
      password: user12
      encoding: utf8
      attributes:
        use_native_enum: true
        default_table_type: INNODB
        default_table_collate: utf8_unicode_ci
        default_table_charset: utf8

我遇到了异常

PDO Connection Error: SQLSTATE[HY000] [2003] Can't connect to MySQL server on '50.115.116.203' (4)

那么配置远程数据库还有什么缺失。

请帮忙

谢谢。

1 个答案:

答案 0 :(得分:0)

192.168.1.100这是本地网络IP,您已将此IP用作您的用户的允许主机。但是,当您使用公共IP地址50.115.116.203连接到此服务器时。 请检查您连接的服务器是否具有与为用户添加的相同的ip作为允许的主机

相关问题