CodeIgniter Forums
mysql connection refused - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: Installation & Setup (https://forum.codeigniter.com/forum-9.html)
+--- Thread: mysql connection refused (/thread-71014.html)



mysql connection refused - jameshking - 06-26-2018

I am a beginner with CI and I am working my way through the tutorials on your site as well as some others I found through googling.  Everything works fine until I encounter a part of the tutorial that requires interface to mysql.  I have tried many suggestions found through googling, but so far nothing works.  I have a simple controller that echos Hello world and then tries to $this->load->database();  This fails with connection refused error.  This is my current database connection configuration:
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost:/db01/var/lib/mysql/mysql.sock',
'username' => 'jking',
'password' => 'mypassword',
'database' => 'citut',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => FALSE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array()
);

As you can see, the location of the database has been moved on this particular server.

Any help would be appreciated.  Thanks


RE: mysql connection refused - jlarroulet - 06-26-2018

(06-26-2018, 03:36 PM)jameshking Wrote: I am a beginner with CI and I am working my way through the tutorials on your site as well as some others I found through googling.  Everything works fine until I encounter a part of the tutorial that requires interface to mysql.  I have tried many suggestions found through googling, but so far nothing works.  I have a simple controller that echos Hello world and then tries to $this->load->database();  This fails with connection refused error.  This is my current database connection configuration:
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost:/db01/var/lib/mysql/mysql.sock',
'username' => 'jking',
'password' => 'mypassword',
'database' => 'citut',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => FALSE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array()
);

As you can see, the location of the database has been moved on this particular server.

Any help would be appreciated.  Thanks

Hi!
This doesn't look like a CI issue. My first (relatively educated) guess would be that the hostname should be just 'localhost' instead of localhost:/db01/var/lib/mysql/mysql.sock

just to make sure, could you confirm that the mysql service is running on the same machine as your application?

do you have SSH access to your server? If yes, can you log in and then try to log into it by typing 
mysql -h localhost -u jking -pmypassword (no space between -p and mypassword)
If you can in fact log in, we can at least rule out a credentials issue.

If you are on shared hosting environments (Dreamhost comes to mind) keep in mind that many won't accept using 'localhost' as the db hostname even if your code and your DB are on the same server (Dreamhost, for instance, forces you to use a FQDN for the database, which usually defaults to mysql.yourdomain.com). Check if your hosting provider has a similar constraint in place or try replacing 'localhost' as the hostname in your CI configuration with the actual IP or hostname of the db server

let me know if anything from the above works Smile


RE: mysql connection refused - jameshking - 06-26-2018

(06-26-2018, 03:36 PM)jameshking Wrote: I am a beginner with CI and I am working my way through the tutorials on your site as well as some others I found through googling.  Everything works fine until I encounter a part of the tutorial that requires interface to mysql.  I have tried many suggestions found through googling, but so far nothing works.  I have a simple controller that echos Hello world and then tries to $this->load->database();  This fails with connection refused error.  This is my current database connection configuration:
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost:/db01/var/lib/mysql/mysql.sock',
'username' => 'jking',
'password' => 'mypassword',
'database' => 'citut',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => FALSE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array()
);

As you can see, the location of the database has been moved on this particular server.

Any help would be appreciated.  Thanks
I have all access to my server and mysql.  I am able to login to mysql locally on the server with my credentials.  I am also able to login to mysql remotely  with a couple of products like sequelpro using the same credentials.  I have not tried replacing localhost with 127.0.0.1, but i will try that.


RE: mysql connection refused - InsiteFX - 06-27-2018

Create a new php file in where index.php is and add this then run it to test your connect.

PHP Code:
$servername "localhost";
$username   "username";
$password   "password";

// Create connection
$db = new mysqli($servername$username$password);

// Check connection
if ($db->connect_error)
{
 
   exit("Connection failed: " $db->connect_error);


echo 
"Connected successfully"



RE: mysql connection refused - jameshking - 06-27-2018

(06-27-2018, 03:09 AM)InsiteFX Wrote: Create a new php file in where index.php is and add this then run it to test your connect.

PHP Code:
$servername "localhost";
$username   "username";
$password   "password";

// Create connection
$db = new mysqli($servername$username$password);

// Check connection
if ($db->connect_error)
{
 
   exit("Connection failed: " $db->connect_error);


echo 
"Connected successfully"

OK, after a lot of experimentation with your code above, I discovered that I was overthinking the problem.  Apparently, the complex string localhost:/db01/var/lib/mysql/mysql.sock is only required when attempting to connect to the database remotely.  Cut it down to just localhost and everything works now.  Thanks for your help.


RE: mysql connection refused - alamowais - 07-24-2018

You are working on localhost so your user must be root and password must empty

$db['default']['hostname'] = 'localhost:8080';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'ci_doctrine';
$db['default']['dbdriver'] = 'mysql';