drush sql-sync 上的访问被拒绝(远程用户和数据库用户不同)

Access denied (remote-user and database user are different) on drush sql-sync

双方都使用 Drush v8.0.3(本地是 Mac,desarrollo 是带有 CPanel 的 Linux 服务器),我正在执行:

sql-sync @project.local @project.desarrollo

并在过程结束时出现此错误(其他一切正常):

ERROR 1045 (28000): Access denied for user 'myremotehostuser'@'localhost' (using password: YES)

我的别名文件包括:

$aliases['desarrollo'] = array (
  'root' => '/home/myremotehostuser/subdomains/project/',
  'uri' => 'http://project.myremotehost.com',
  'remote-user' => 'myremotehostuser',
  'remote-host' => 'myremotehost.com',
  'path-aliases' => array(
    '%dump-dir' => '/tmp',
  ),
  'source-command-specific' => array (
    'sql-sync' => array (
      'no-cache' => TRUE,
      'structure-tables-key' => 'common',
    ),
  ),
  'command-specific' => array (
    'sql-sync' => array (
      'sanitize' => TRUE,
      'no-ordered-dump' => TRUE,
      'structure-tables' => array(
        'common' => array('cache', 'cache_filter', 'cache_menu', 'cache_page', 'history', 'sessions', 'watchdog'),
      ),
    ),
  ),
);

"desarrollo" returns:

状态
Drupal version         :  7.41                                   
Site URI               :  http://project.myremotehost.com       
Database driver        :  mysql                                  
Database hostname      :  localhost                              
Database port          :                                         
Database username      :  databaseuser                         
Database name          :  databasename                      
PHP configuration      :  /usr/local/lib/php.ini                 
PHP OS                 :  Linux                                  
Drush script           :  /usr/local/bin/drush                   
Drush version          :  8.0.3                                  
Drush temp directory   :  /tmp                                   
Drush configuration    :                                         
Drush alias files      :                                         
Drupal root            :  /home/myremotehostuser/subdomains/project/ 
Drupal Settings File   :  sites/default/settings.php             
Site path              :  sites/default  

如您所见,"database owner"(MySQL 用户)与 "remote-host"(CPanel 用户)不同。

Drush 应该扫描两侧的设置文件以找出正确的配置,如果我没记错的话,您甚至不必添加 $databases 数组或 db-url 字符串自 v7.然后,为什么它尝试使用 'myremotehostuser'@'localhost' 而不是 'databaseuser'@'localhost'?[=15= 访问数据库]

在这种情况下,没有名为 'myremotehostuser' 的数据库用户,我想我可以通过创建它并授予 'databasename' 权限来解决问题,但我几乎可以肯定我是这里遗漏了一些非常愚蠢的东西,必须有一个简单的解决方案。

编辑:

尝试在主机用户名和数据库用户名仍然不同的同一台服务器中使用相同的别名文件,但这次是在新创建的帐户中,似乎工作得很好。所以我猜这个问题是由一些 CPanel/WHM 配置问题引起的,而不是任何与 Drush 相关的事情。在关闭问题之前,我会继续尝试几次。

在新帐户中重复 rsync 和 sql-sync 过程没有问题。该问题仅发生在这个已创建的帐户中,该帐户具有多个数据库、用户和前缀。我没有此帐户的完全访问权限,因此无法正确测试它。

这个问题太具体了,可能不值得单独提出问题,因为它几乎不可能复制。我会考虑它 "solved" 并会在我发现它不起作用的原因时更新它。

我也遇到了这个问题。事实证明 drush 首先寻找文件 ~/.my.cnf,如果找到,它将使用它进行连接。该文件包含用户名和密码。

[client]
user=myremotehostuser

一旦我暂时删除了这个文件,drush 就可以使用站点的 settings.php.

成功转储 sql