duanbo6871 2015-05-05 11:50
浏览 38

Openshift MySQL Cartgridge上的连接超时

I'm deploying a PHP app which uses Doctrine as ORM in Openshift. In my post_deploy action hook I run doctrine orm schema-tool to update the DB but I'm getting a Connection Timeout error. As I'm farily new to Openshift, what is the best way to setup the database on Openshift?

UPDATE I have two gears, one for the app and other for MySQL. I ssh into the app gear and ran

doctrine orm:schema-tool:update

Which results in a Connection Timeout error. If I try

  mysql -h $OPENSHIFT_MYSQL_DB_HOST
        -p $OPENSHIFT_MYSQL_DB_PORT 
        -u $OPENSHIFT_MYSQL_DB_USERNAME 
        -P $OPENSHIFT_MYSQL_DB_PASSWORD
        -

I get a prompt and the subsequent error after entering the MySQL password informed by Openshift.

Enter password: 
ERROR 1049 (42000): Unknown database '<obsfucated_password>'

UDPATE 2: As an unrelated thing pointed by Martin below, the mysql syntax is wrong. After fixing it I found that

 mysql -u $OPENSHIFT_MYSQL_DB_USERNAME
       -h $OPENSHIFT_MYSQL_DB_HOST
       -P $OPENSHIFT_MYSQL_DB_PORT
       -D $OPENSHIFT_APP_NAME 
       -p $OPENSHIFT_MYSQL_DB_PASSWORD

Results in

Enter password: 
ERROR 1045 (28000): Access denied for user 'adminjbEnwMq'@'10.63.71.68' (using password: NO)

While runnning

mysql -u $OPENSHIFT_MYSQL_DB_USERNAME -h $OPENSHIFT_MYSQL_DB_HOST -P $OPENSHIFT_MYSQL_DB_PORT -D $OPENSHIFT_APP_NAME

Connects successfully.

UPDATE 3 On the PHP side I'm running the following test code, thanks to this answer:

  <?php

    require_once "vendor/autoload.php";
    require_once "vendor/doctrine/common/lib/Doctrine/Common/ClassLoader.php";
    use Doctrine\DBAL\Configuration;

    $config = new \Doctrine\DBAL\Configuration();

    define('DB_HOST', getenv('OPENSHIFT_MYSQL_DB_HOST'));
    define('DB_PORT',getenv('OPENSHIFT_MYSQL_DB_PORT')); 
    define('DB_USER',getenv('OPENSHIFT_MYSQL_DB_USERNAME'));
    define('DB_PASS',getenv('OPENSHIFT_MYSQL_DB_PASSWORD'));
    define('DB_NAME',getenv('OPENSHIFT_GEAR_NAME'));
    $connectionParams = array(
        'dbname' => DB_NAME,
        'user' => DB_USER,
        'password' => DB_PASS,
        'host' => DB_HOST,
        'driver' => 'pdo_mysql',
    );
    $conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);
    var_dump($conn);
    echo $conn->query("SHOW TABLES"); 
?>

And I get the same timeout error.

  • 写回答

2条回答 默认 最新

  • dongzhuo3059 2015-05-06 10:40
    关注

    I cannot help you with your doctrine question, but the mysql command syntax is actually wrong.

    Usage: mysql [OPTIONS] [database]
    

    As you can see in your output, mysql is interpreting your password as the database name.

    If you want to specify the optionas as you showed above you need to add an '=' between the option and the option-value.

    mysql --host=$OPENSHIFT_MYSQL_DB_HOST
          --port=$OPENSHIFT_MYSQL_DB_PORT 
          --user=$OPENSHIFT_MYSQL_DB_USERNAME 
          --password=$OPENSHIFT_MYSQL_DB_PASSWORD
    

    If you want to add the database name to your command, the default database name is $OPENSHIFT_APP_NAME. Just add it at the end of your mysql command.

    To see all the mysql options do mysql --help

    评论

报告相同问题?

悬赏问题

  • ¥15 对于这个复杂问题的解释说明
  • ¥50 三种调度算法报错 采用的你的方案
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败