Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Installing SilverStripe /

Getting SilverStripe up and running on your computer and on your web server.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Can't connect to MySQL server on '127.0.0.1' (111)


Go to End


2896 Views

Avatar
Fraser

Community Member, 48 Posts

5 May 2015 at 3:39am

Firstly please apologies for how vague this post may be but I'm completely at a loss as to what could be occurring here.

I've been having an issue with a site I've developed for a client where it seemingly, randomly loses connection to the MySQL server and requires a reboot of the server for the site to become available again.. I've a number of other SS sites in my portfolio and not a single other one has experienced this before.

The site can run for a few days or an hour or sometimes a couple of weeks before having this issue and I've not been able to pin down what actually triggers it, though it appears to be related to some kind of usage of the CMS. The client will report that it will lose the connection when he's trying to upload a photo or write a blog post. I've posted the error at the bottom of the post to not clutter things.

Thinking it was an issue with the server set up, I set up a brand new digital ocean droplet and migrated the site over to there, but the issue remains so it leads me to believe it's something within the framework or my site config (old server was running on CentOs and the new one is Ubuntu).

This is the only site I have set up using composer. A novice to composer, I followed the instructions on the SS site to achieve this. My composer.json is below. Does it look like I have any issues here?:

{
	"name": "silverstripe/installer",
	"description": "The SilverStripe Framework Installer",
	"require": {
		"php": ">=5.3.2",
		"silverstripe/cms": "3.1.6",
		"silverstripe/framework": "3.1.6",
		"silverstripe-themes/simple": "*",
		"silverstripe/blog": "dev-master",
		"undefinedoffset/sortablegridfield": "dev-master"
	},
	"config": {
		"process-timeout": 600	
	},
	"minimum-stability": "dev"
}

I've not made any changes to the core. Nothing unusual in there but my _config.php is:

<?php

global $project;
$project = 'mysite';

global $databaseConfig;
$databaseConfig = array(
	"type" => 'MySQLDatabase',
	"server" => 'localhost',
	"username" => 'root',
	"password" => 'xxxxxx',
	"database" => 'mysite',
	"path" => '',
);

// Set the site locale
i18n::set_locale('en_US');
Director::set_environment_type('dev');
Security::setDefaultAdmin("fraser","xxxxxxx");

Can anyone think of any reason why the connection would be dropping to the MySQL server? Is there anything else I should check? Do you need any more information from me?

[Warning] mysqli::mysqli(): (HY000/2003): Can't connect to MySQL server on '127.0.0.1' (111)

GET /

Line 68 in /var/www/mysite/framework/model/MySQLDatabase.php

Source

59 	 *  - password: The password to log on with
60 	 *  - database: The database to connect to
61 	 *  - timezone: (optional) The timezone offset. For example: +12:00, "Pacific/Auckland", or "SYSTEM"
62 	 */
63 	public function __construct($parameters) {
64 		if(!empty($parameters['port'])) {
65 			$this->dbConn = new MySQLi($parameters['server'], $parameters['username'], $parameters['password'],
66 				'', $parameters['port']);
67 		} else {
68 			$this->dbConn = new MySQLi($parameters['server'], $parameters['username'], $parameters['password']);
69 		}
70 
71 		if($this->dbConn->connect_error) {
72 			$this->databaseError("Couldn't connect to MySQL database | " . $this->dbConn->connect_error);
73 		}
74 		
Trace

mysqli->mysqli(<filtered>,<filtered>,<filtered>) 
MySQLDatabase.php:68
MySQLDatabase->__construct(Array) 
DB.php:174
DB::connect(<filtered>) 
main.php:127
{closure}(ErrorControlChain) 
call_user_func(Closure,ErrorControlChain) 
ErrorControlChain.php:125
ErrorControlChain->step() 
ErrorControlChain.php:117
ErrorControlChain->execute() 
main.php:154
require_once(/var/www/mysite/framework/main.php) 
index.php:65
[User Error] Couldn't connect to MySQL database | Can't connect to MySQL server on '127.0.0.1' (111)

GET /

Line 598 in /var/www/mysite/framework/model/MySQLDatabase.php

Source

589 	}
590 
591 	public function databaseError($msg, $errorLevel = E_USER_ERROR) {
592 		// try to extract and format query
593 		if(preg_match('/Couldn\'t run query: ([^\|]*)\|\s*(.*)/', $msg, $matches)) {
594 			$formatter = new SQLFormatter();
595 			$msg = "Couldn't run query: \n" . $formatter->formatPlain($matches[1]) . "\n\n" . $matches[2];
596 		}
597 
598 		user_error($msg, $errorLevel);
599 	}
600 
601 	/**
602 	 * Return a boolean type-formatted string
603 	 *
604 	 * @param array $values Contains a tokenised list of info about this data type
Trace

Couldn't connect to MySQL database | Can't connect to MySQL server on '127.0.0.1' (111) 
MySQLDatabase.php:598
MySQLDatabase->databaseError(Couldn't connect to MySQL database | Can't connect to MySQL server on '127.0.0.1' (111)) 
MySQLDatabase.php:72
MySQLDatabase->__construct(Array) 
DB.php:174
DB::connect(<filtered>) 
main.php:127
{closure}(ErrorControlChain) 
call_user_func(Closure,ErrorControlChain) 
ErrorControlChain.php:125
ErrorControlChain->step() 
ErrorControlChain.php:117
ErrorControlChain->execute() 
main.php:154
require_once(/var/www/mysite/framework/main.php) 
index.php:65