2
votes

until last week magento cron was working fine. Suddenly it started giving following error. I have checked my local.xml and database username, password and all these things are there. My site is working fine. The error only happen in cron. Cron is working fine.. I am getting email from cron with the following error. When i run cron.php in browser two times it starts and executes jobs. Please help how to resolve this issue to run cron properly.

X-Powered-By: PHP/5.2.17 Content-type: text/html


Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)' in /home/home/public_html/mydir/lib/Zend/Db/Adapter/Pdo/Abstract.php:129 Stack trace:

#0 /home/home/public_html/mydir/lib/Zend/Db/Adapter/Pdo/Abstract.php(129): PDO->__construct('mysql:host=loca...', 'database name', 'database password', Array)
#1 /home/home/public_html/mydir/lib/Zend/Db/Adapter/Pdo/Mysql.php(96): Zend_Db_Adapter_Pdo_Abstract->_connect()
#2 /home/home/public_html/mydir/lib/Varien/Db/Adapter/Pdo/Mysql.php(313): Zend_Db_Adapter_Pdo_Mysql->_connect()
#3 /home/home/public_html/mydir/lib/Zend/Db/Adapter/Abstract.php(459): Varien_Db_Adapter_Pdo_Mysql->_connect()
#4 /home/home/public_html/mydir/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('SET NAMES utf8', Array)
#5 /home/home/public_html/mydir/lib/Varien/Db/Adapter/Pdo/Mysql.php(419): Zend_Db_Adapter_Pdo_Abstra in <b>/home/home/public_html/mydir/lib/Zend/Db/Adapter/Pdo/Abstract.php</b> on line <b>144</b><br />

I really need to run my cron job. Thanks in advance

2

2 Answers

8
votes

I had exactly the same issue as you, and doing the following worked for me:

1) Edit the app/etc/local.xml file in your Magento folder, replacing the entry for the host to be '127.0.0.1' instead of 'localhost'.

2) Delete the var/cache directory in your Magento folder.

Accessing your Magento site will rebuild the cache, and your jobs should hopefully now be working.

I too was pulling my hair out with this one and found your post looking for the answer! I'd changed the hostname earlier in trying to fix the problem, and later found that it wasn't having any effect. Trashing the cache fixed this, and now everything appears to be working properly.

0
votes

For Magento2, editing your env.php file should resolve it.

It is located under the /opt/lampp/htdocs/magento/app/etc/ directory.

All you need to do is to change localhost to 127.0.0.1.