尝试将 phpMyAdmin 连接到远程 mySQL 服务器(2002:无法连接)

尝试将 phpMyAdmin 连接到远程 mySQL 服务器(2002:无法连接)

尝试让 phpMyAdmin 与远程 mySQL 服务器通信。配置如下,mySQL DB 中已设置用户,以便能够从 PMA 所在的指定主机登录。托管由 Rackspace (Rightscale) 提供,两个云服务器都位于同一防火墙后面。

[配置.inc.php]

<?php

  $cfg['blowfish_secret'] = '';
  $i = 0;

  $i++;
  $cfg['Servers'][$i]['host']          = 'XX.XX.XX.XX';   // MySQL hostname or IP address
  $cfg['Servers'][$i]['port']          = '';                 // MySQL port - leave blank for default port
  $cfg['Servers'][$i]['socket']        = '';                 // Path to the socket - leave blank for default socket
  $cfg['Servers'][$i]['connect_type']  = 'tcp';              // How to connect to MySQL server ('tcp' or 'socket')
  $cfg['Servers'][$i]['extension']     = 'mysql';            // The php MySQL extension to use ('mysql' or 'mysqli')
  $cfg['Servers'][$i]['compress']      = FALSE;              // Use compressed protocol for the MySQL connection
                                                             // (requires PHP >= 4.3.0)
  $cfg['Servers'][$i]['controluser']   = '';                 // MySQL control user settings
                                                             // (this user must have read-only
  $cfg['Servers'][$i]['controlpass']   = '';                 // access to the "mysql/user"
                                                             // and "mysql/db" tables).
                                                             // The controluser is also
                                                             // used for all relational
                                                             // features (pmadb)
  $cfg['Servers'][$i]['auth_type']     = 'config';           // Authentication method (config, http or cookie based)?
  $cfg['Servers'][$i]['user']          = 'USERNAME';              // MySQL user
  $cfg['Servers'][$i]['password']      = 'PASSWORD';  // MySQL password (only needed
                                                             // with 'config' auth_type)
  $cfg['Servers'][$i]['only_db']       = '';                 // If set to a db-name, only
                                                             // this db is displayed in left frame
                                                             // It may also be an array of db-names, where sorting order is relevant.
  $cfg['Servers'][$i]['hide_db']       = '';                 // Database name to be hidden from listings
  $cfg['Servers'][$i]['verbose']       = '';                 // Verbose name for this host - leave blank to show the hostname

  $cfg['Servers'][$i]['pmadb']         = '';                 // Database used for Relation, Bookmark and PDF Features
                                                             // (see scripts/create_tables.sql)
                                                             //   - leave blank for no support
                                                             //     DEFAULT: 'phpmyadmin'
  $cfg['Servers'][$i]['bookmarktable'] = '';                 // Bookmark table
                                                             //   - leave blank for no bookmark support
                                                             //     DEFAULT: 'pma_bookmark'
  $cfg['Servers'][$i]['relation']      = '';                 // table to describe the relation between links (see doc)
                                                             //   - leave blank for no relation-links support
                                                             //     DEFAULT: 'pma_relation'
  $cfg['Servers'][$i]['table_info']    = '';                 // table to describe the display fields
                                                             //   - leave blank for no display fields support
                                                             //     DEFAULT: 'pma_table_info'
  $cfg['Servers'][$i]['table_coords']  = '';                 // table to describe the tables position for the PDF schema
                                                             //   - leave blank for no PDF schema support
                                                             //     DEFAULT: 'pma_table_coords'
  $cfg['Servers'][$i]['pdf_pages']     = '';                 // table to describe pages of relationpdf
                                                             //   - leave blank if you don't want to use this
                                                             //     DEFAULT: 'pma_pdf_pages'
  $cfg['Servers'][$i]['column_info']   = '';                 // table to store column information
                                                             //   - leave blank for no column comments/mime types
                                                             //     DEFAULT: 'pma_column_info'
  $cfg['Servers'][$i]['history']       = '';                 // table to store SQL history
                                                             //   - leave blank for no SQL query history
                                                             //     DEFAULT: 'pma_history'
  $cfg['Servers'][$i]['verbose_check'] = TRUE;               // set to FALSE if you know that your pma_* tables
                                                             // are up to date. This prevents compatibility
                                                             // checks and thereby increases performance.
  $cfg['Servers'][$i]['AllowRoot']     = TRUE;               // whether to allow root login
  $cfg['Servers'][$i]['AllowDeny']['order']                  // Host authentication order, leave blank to not use
                                       = '';
  $cfg['Servers'][$i]['AllowDeny']['rules']                  // Host authentication rules, leave blank for defaults
                                       = array();

如果您需要更多信息,请告诉我。

-- 马尔科姆

答案1

通过将“xx.xx.xx.xx”替换为远程 mysql 服务器的 ip 地址来进行检查,并确保允许数据库通过您的 ip 地址访问。

$cfg['服务器'][$i]['主机'] = 'XX.XX.XX.XX';

答案2

可能有以下几种因素在起作用:

  1. 应用程序本身使用的源地址与您从命令行连接到 MySQL 服务器的源地址不同。如果服务器和应用程序彼此位于本地,则可能是127.0.0.1vs的简单混淆localhost,MySQL 将其视为不同的主机,因此它们需要不同的权限掩码。同样,如果您的 Web 应用程序在防火墙后面进行 SNAT,则 MySQL 很可能会看到不同的源 IP。

  2. 另一个常见的麻烦是使用权限掩码中的 DNS 主机名。如果您这样做(例如'user'@'foo.bar.com'),并且 DNS 解析失败或您的正向/反向记录不匹配,MySQL 将不允许连接。

如果上述情况都不是,您也可以尝试暂时放宽权限,'user'@'%'看看是否能缓解问题。

相关内容