CodeIgniter Forums
Unable to connect to MySQL (yet again) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Unable to connect to MySQL (yet again) (/showthread.php?tid=11765)

Pages: 1 2


Unable to connect to MySQL (yet again) - El Forum - 09-22-2008

[eluser]Don Faulkner[/eluser]
Hi all,

Sorry that my first post is a repeat of a common question, but I can't seem to find an exact match in the forums.

I'm trying out CodeIgniter 1.6.3, using my Mac (and a linux box, and a solaris box, but today we're talking about the Mac).
I'm following the blog tutorial (which I realize is a bit out of date), and I've built a database and tried to connect to it, but I keep getting the following error:
Quote:A Database Error Occurred. Unable to connect to your database server using the provided settings.

Now, for what I've done:
1. In autoload, I've tried both autoload['libraries'] and autoload['core']. I don't get the error with core until I try to load scaffolding.
2. I've tried setting pconnect to FALSE. I've tried setting active_record to FALSE. No luck.
3. I've checked (and re-checked and re-re-checked the username & password. using codeigniter@localhost, password codeigniter I can log into my database using other tools.

My setup
Mac OS X 10.5 ("Leopard")
MySQL 5.0.67
PHP 5.2.6


Here is the $db array from my database.php file:
Code:
$db['default']['hostname'] = "localhost";
$db['default']['username'] = "codeigniter";
$db['default']['password'] = "codeigniter";
$db['default']['database'] = "blog";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";
What might I have missed?


Unable to connect to MySQL (yet again) - El Forum - 09-22-2008

[eluser]jcopling[/eluser]
I suppose it's best to start in the simplest place. Is MySQL service running?


Unable to connect to MySQL (yet again) - El Forum - 09-22-2008

[eluser]Don Faulkner[/eluser]
Yup, the MySQL service is running. :-) I can test connectivity in my GUI tool or command line, then hit refresh in my browser and get the error.


Unable to connect to MySQL (yet again) - El Forum - 09-22-2008

[eluser]jcopling[/eluser]
What service are you using for localhost?


Unable to connect to MySQL (yet again) - El Forum - 09-22-2008

[eluser]Don Faulkner[/eluser]
I don't understand. What do you mean by "service" here? The process name is safe_mysqld.

Hmm. It also occurred to me to mention that I'm using the 64-bit version of mysql.


Unable to connect to MySQL (yet again) - El Forum - 09-22-2008

[eluser]jcopling[/eluser]
Well, because the host of your DB is listed as 'localhost', I am assuming that you are working on your site located at http://localhost/ . Is this correct?

If so, then I was also assuming that you were running localhost with a program such as XAMPP or something similar.


Unable to connect to MySQL (yet again) - El Forum - 09-22-2008

[eluser]Don Faulkner[/eluser]
Oh, yes. No ISP at this point, just my local machine.
I'm not using XAMPP, just the default Apache 2.2.8 and PHP 5.2.6. Here's my apache version string:
Code:
Apache/2.2.8 (Unix) mod_ssl/2.2.8 OpenSSL/0.9.7l DAV/2 PHP/5.2.6
But yes, everything is on localhost. Default Mac OS X apache & php. Loaded MySQL. Developing in $HOME/Sites/

So, I can hit http://localhost/~don/ to get my default controller.

Also, the error occurs whether I use /~don/ or /~don/index.php/blog/


Unable to connect to MySQL (yet again) - El Forum - 09-22-2008

[eluser]jcopling[/eluser]
Is there a root password set for MySQL and if so have you tried connecting with those credentials? If not, you may want to try connecting with:

Code:
$db['default']['username'] = "root";
$db['default']['password'] = ""; //or use root password if set

The only reason this may work is if the user 'codeigniter' does not have the appropriate permissions for some reason.

Also, you may want to try a native mysql_connect to see if this will work outside of the CI framework.

Code:
mysql_connect('localhost', 'codeignitor', 'codeigniter') or die('Could not connect: ' . mysql_error();

Also, turn your error log on and see if you can get a more specific error message from that.


Unable to connect to MySQL (yet again) - El Forum - 09-22-2008

[eluser]Don Faulkner[/eluser]
Found the problem.

The mysql socket is not where php was expecting it to be. I changed hostname to 127.0.0.1 (instead of localhost), to effectively trick the connection over to the TCP/IP side and things are working now.

Sorry for the trouble. The differences between TCP/IP and Unix sockets can really get to me, especially as I move between platforms.


Unable to connect to MySQL (yet again) - El Forum - 09-22-2008

[eluser]jcopling[/eluser]
Glad you got it working in spite of all my help. Smile