简体   繁体   English

codeigniter-无法连接到MySQL数据库

[英]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. 我的database.php文件中的所有信息都与我在命令行上运行的mysql服务器上的信息匹配。 I am also using mysqld and mysql.server start . 我也在使用mysqldmysql.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. 这似乎可以在我的命令行上使用,但是当我在我用codeigniter项目设置的本地主机服务器上引用它时,它给了我上面的错误。 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 另外,我在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. 我自己经常使用CodeIgniter遇到此问题。 The usual solution (for me!) is to set 'pconnect' and 'db_debug' to FALSE: 通常的解决方案(对我来说)是将'pconnect'和'db_debug'设置为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. 我试图在config / database.php文件中更改以下行,并且它起作用了。 (The error your getting means something is wrong with your config/database.php) (您得到的错误意味着您的config / database.php出了点问题)

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

Explanation for this behaviour is written here (MySQL on OSX finds mysql.sock wrongly). 此行为的解释写在这里 (OSX上的MySQL错误地找到mysql.sock)。

Cheers! 干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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