简体   繁体   中英

codeigniter - cannot connect to MySQL database

Error that is getting printed out

Unable to connect to your database server using the provided settings.

Filename: core/Loader.php

Line Number: 346

I have been looking through all the other questions and nothing seems to work. Still getting this error. All the info in my database.php file matched up to my info on the mysql server that I am running on the command line. I am also using mysqld and mysql.server start . I have tested the connection on the command line with

mysql -h localhost -uroot -p dbname

And that seems to work on my command line, but it is giving me the error above when I am referencing it on a localhost server I have set up with the codeigniter project. What am i doing wrong? I have double and triple checked naming conventions to make sure that it isn't the issue.

Also, I am on OS X Mavericks

my code in the config file is as follows:

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = 'PASS';
$db['default']['database'] = 'dbname';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

I have run into this problem frequently myself with CodeIgniter. The usual solution (for me!) is to set 'pconnect' and 'db_debug' to FALSE:

$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = FALSE;

I tried to change the following line in my config/database.php file and it worked. (The error your getting means something is wrong with your config/database.php)

'hostname' => '/Applications/MAMP/tmp/mysql/mysql.sock',

Explanation for this behaviour is written here (MySQL on OSX finds mysql.sock wrongly).

Cheers!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM