简体   繁体   中英

CakePHP 2 cannot connection with MySQL

I am trying to set up CakePHP 2 in my virtually owned server. The only step missing is connecting MySQL. I've edited my database.php file to include the following.

'datasource' => 'Database/Mysql',
    'persistent' => false,
    'database' => 'paulncks_money',
    'host' => 'server189.web-hosting.com',
    'login' => 'paulncks_teller',
    'password' => '**********',

However, cake php gives me this error

Error: A Database connection using "Mysql" was missing or unable to connect.    

The database server returned this error: SQLSTATE[HY000] [2006] MySQL server has gone away

I've migrated my database onto the server and tried every possible hostname.

One possible fix

I tried being more specific and included the port on my hostname.

'host' => 'server189.web-hosting.com',

This change returned a new set of errors. I don't know if I am any closer to solving my problem, but these errors are so bizzare.

Warning (2): Packets out of order. Expected 0 received 80. Packet 
size=5526600 [CORE/Cake/Model/Datasource/Database/Mysql.php, line 184]
Warning (2): PDO::__construct() [<a 
href='http://php.net/pdo.construct'>pdo.construct</a>]: MySQL server has 
gone away [CORE/Cake/Model/Datasource/Database/Mysql.php, line 184]
Warning (2): PDO::__construct() [<a 
href='http://php.net/pdo.construct'>pdo.construct</a>]: Error while reading 
greeting packet. PID=294504 [CORE/Cake/Model/Datasource/Database/Mysql.php, 
line 184]

Am I closer to connecting?

May be i'm too late but this can help some one else

Possible reasons for SQLSTATE[HY000] [2006]

The most common of them is (point 4 from the link) :

max_allowed_packet = 1M

Try to increase to 4M, 8M or 16M (to do that you need access to mysql config file)

One advice don't show mysql server settings (host, login and so on)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM