Magento 1.8 MySQL Server Connection Issues – How to Fix

amazon-web-servicesapachemagento-1.8MySQL

Hi i have my magento running in amazon ec2 linux instance but frequently i get errors stating below mentioned errors

SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (111)

Trace:
#0 /var/www/html/trial/lib/Zend/Db/Adapter/Pdo/Mysql.php(96): Zend_Db_Adapter_Pdo_Abstract->_connect()
#1 /var/www/html/trial/lib/Varien/Db/Adapter/Pdo/Mysql.php(320): Zend_Db_Adapter_Pdo_Mysql->_connect()
#2 /var/www/html/trial/lib/Zend/Db/Adapter/Abstract.php(459): Varien_Db_Adapter_Pdo_Mysql->_connect()
#3 /var/www/html/trial/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('SET NAMES utf8', Array)
#4 /var/www/html/trial/lib/Varien/Db/Adapter/Pdo/Mysql.php(428): Zend_Db_Adapter_Pdo_Abstract->query('SET NAMES utf8', Array)
#5 /var/www/html/trial/app/code/core/Mage/Core/Model/Resource.php(169): Varien_Db_Adapter_Pdo_Mysql->query('SET NAMES utf8')
#6 /var/www/html/trial/app/code/core/Mage/Core/Model/Resource.php(110): Mage_Core_Model_Resource->_newConnection('pdo_mysql', Object(Mage_Core_Model_Config_Element))
#7 /var/www/html/trial/app/code/core/Mage/Core/Model/Resource/Setup.php(141): Mage_Core_Model_Resource->getConnection('core_setup')
#8 /var/www/html/trial/app/code/core/Mage/Core/Model/Resource/Setup.php(234): Mage_Core_Model_Resource_Setup->__construct('core_setup')
#9 /var/www/html/trial/app/code/core/Mage/Core/Model/App.php(417): Mage_Core_Model_Resource_Setup::applyAllUpdates()
#10 /var/www/html/trial/app/code/core/Mage/Core/Model/App.php(343): Mage_Core_Model_App->_initModules()
#11 /var/www/html/trial/app/Mage.php(684): Mage_Core_Model_App->run(Array)
#12 /var/www/html/trial/index.php(87): Mage::run('', 'store')
#13 {main}

But once if i restart my apache and mysql again my site starts working perfectly and after some time the same error occurs initially my site was running in localhost after migrating to amazon linux instance i changed the secure base url and unsecure base url pointing towards my amazon linux instance public ip.

I have tried reindexing data.

so my question is
1.Where do i need to make changes so that my mysql will connect to my public ip instead of localhost(127.0.0.1).
2.what should i do so that this error won't happen again.

Thanks in advance.

Best Answer

Is sounds like your MySQL process is dropping. If you're running MySQL and Apache on the same instance and it's running out of memory the MySQL process will be killed.

2 solutions:

  1. Split your web and database nodes (On AWS look at RDS)
  2. Go for a bigger AWS instance with more memory
Related Topic