CodeIgniter Forums
MySql Connection Fail [resolved] - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: MySql Connection Fail [resolved] (/thread-23099.html)



MySql Connection Fail [resolved] - El Forum - 09-30-2009

[eluser]koringa[/eluser]
Hello Guys,

I use MacOS and trying to connect my project to the MySQL database using the Code Iginiter. I can connect from the command line or any others program, for example Sequel Pro for Mysql Database Administration, that is, my database works and is running normally.

In my autoload.php I set point to autoload database.

Code:
$autoload['libraries'] = array("database","session");

Below is my database.php

Code:
$active_group = "default";
$active_record = TRUE;

$db['default'][ 'hostname'] = "localhost";
$db['default'][ 'username'] = "root";
$db['default'][ 'password'] = "****";
$db['default'][ 'database'] = "sitesp";
$db['default'][ 'dbdriver'] = "mysql";
$db['default'][ 'dbprefix'] = "";
$db['default'][ 'pconnect'] = TRUE;
$db['default'][ 'db_debug'] = TRUE;
$db['default'][ 'cache_on'] = FALSE;
$db['default'][ 'cached'] = "";
$db['default'][ 'CHAR_SET'] = "utf8";
$db['default'][ 'dbcollat'] = "utf8_general_ci";

The database "sitesp" was created, of course.

Just get the message:

A Database Error Occurred
Unable to select the specified database: sitesp


If anyone has been there, will help a lot.

Thank you and anything I can, post here too.
[]
Thanks


MySql Connection Fail [resolved] - El Forum - 09-30-2009

[eluser]jedd[/eluser]
Hi koringa and welcome to the CI forums.


Quote:I can connect from the command line or any others program, for example Sequel Pro for Mysql Database Administration, that is, my database works and is running normally.

Do you connect, at the commandline, using root, or a normal user account?

You should not be using root (as specified in your config.php above) as it's a touch insecure. Create an account for this app, with a different password, etc.

For the time, try this:

Code:
$   mysql  -u root -h localhost -p sitesp

And confirm you can still connect using your credentials.

I'm not sure how OSX works with local connections, but on some *nix's MySQL will connect through sockets rather than through TCP, which can be confusing because MySQL permissions often include the originating host (name or IP). In any case, the above command line might give some more insight into the nature of the problem.


MySql Connection Fail [resolved] - El Forum - 09-30-2009

[eluser]wabu[/eluser]
Can you (re-)confirm that the database name you specified is correct?


MySql Connection Fail [resolved] - El Forum - 09-30-2009

[eluser]koringa[/eluser]
I'm at work and my Mac at home, but certainly a problem in MacOS as jedd said, as tested here in Windows with the same settings as my project and it worked. I have to check why the error occurs.

wabu, yes, the database is correct.


MySql Connection Fail [resolved] - El Forum - 09-30-2009

[eluser]koringa[/eluser]
jedd,

Resolved as follows:

I edited my .cnf and put the link to the sock, which in my case is

socket = / Applications / MAMP / tmp / mysql / mysql.sock

Thank you all
[]'s