840   CodeIgniter MySQL PHP

环境:
CI版本2.2
PHP版本5.6
mysql版本5.1

通过mysql驱动连数据库报错

A Database Error Occurred
Unable to connect to your database server using the provided settings.

stack overflow 有相关解释

我按照以下方法可以

$db['default']['db_debug'] = TRUE;
to
$db['default']['db_debug'] = FALSE;

其实,最好是先不通过CI,自己手动连接数据库,代码如下


$link = mysql_connect('localhost', 'root', '123456');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);

测试也报错,要疯了

mysql_connect(): [2002] No such file or directory (trying to connect via unix:///tmp/mysql.sock) in

还好 stack overflow 上也有相关解释

就是找到mysql.sock,然后做个软连接到/tmp/mysql.sock

ln -s /var/mysql/mysql.sock /tmp/mysql.sock



Leave a Reply

Your email address will not be published. Required fields are marked *