Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /hermes/bosnacweb04/bosnacweb04ae/b2501/ipg.parminderscom/apps/blog/wp-content/plugins/jetpack/jetpack.php on line 246 mysql at Kirpa Apps Blog

Kirpa Apps Blog

Archive for the ‘mysql’ tag

Symfony Error: PDO Connection Error: SQLSTATE[HY000] [2002]

without comments

PDO Connection Error: SQLSTATE[HY000] [2002] No such file or directory

Warning: PDO::__construct() [pdo.–construct]: [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in

This error occurs when the path to mysql.sock in the php.ini file (in the above case /var/mysql/mysql.sock) is incorrect (Thanks to this link). Please note that there may be multiple copies of php.ini on your system. The php.ini file that the webserver uses needs to be changed. To find which php.ini is your webserver using, use phpinfo(). In my case the location was /etc.

Once the correct php.ini is found, look for the property “pdo_mysql.default_socket” and point to the path where mysql.sock resides. To find where your mysql.sock resides, run this command (Thanks to this link):

[sourcecode language=”sql”]

mysqladmin variables

[/sourcecode]

OR

[sourcecode language=”sql”]mysqld –verbose –help | grep ^socket[/sourcecode]

On my system [Mac running MySql 5.1.50] the location was /tmp/mysql.sock.

Written by admin

December 28th, 2010 at 4:18 pm

Posted in Tech

Tagged with , , , ,

MySQL Communications Link Failure

without comments

Recently we were baffled by the “Communications Link Failure” issue on our servers.

Our setup:

Jahia 6 on Tomcat (Apache DBCP, Spring, Hibernate, MySql).

Here’s what we observed:

1. The exception is generally caused by a connection that has become stale. The connections in the pool become stale after the wait_timeout period set in the my.cnf on the mysql server. The pool implementation should somehow validate connections before using them (which is what validationQuery is for).  However, setting validationQuery has performance side effects.

2.     Setting the autoReconnect (jdbc:mysql://DBHOST/schema?autoReconnect=true) to true on the driver should try to reconnect in case the connection has become stale each time a connection is made. However, this has no effect anymore and can be removed.

After trying a few other options, what helped us was setting the “wait_timeout” value in the my.cnf to a high value. (Some value greater than the max amount of inactivity in the system).

If the wait_timeout is set to a high value so that during the period of inactivity the connections do not become stale, this exception will not be raised.

Of course, the other option is to handle stale connections in your code and recover from such exceptions or use a connection pool implementation that does this for you.

Written by admin

March 30th, 2010 at 2:48 pm