Jquery中文网 www.jquerycn.cn
Jquery中文网 >  脚本编程  >  php  >  正文 php error Can't connect to local MySQL server...的解决方法

php error Can't connect to local MySQL server...的解决方法

发布时间:2014-12-16   编辑:www.jquerycn.cn
php 不能连接数据库 php error Can't connect to local MySQL server through socket '/tmp/mysql.sock'的解决方法

php 不能连接数据库 php error Can't connect to local MySQL server through socket '/tmp/mysql.sock'

测试用的php文件

复制代码 代码如下:
<?php
$link=mysql_connect('localhost','root','zz') or die(mysql_error());
mysql_select_db('test') or die('no db');
mysql_query('SET NAMES utf8');
echo 99;
?>

运行后报错:
Can't connect to local MySQL server through socket '/tmp/mysql.sock'

但在 命令行中能进入mysql
[root@localhost local]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 3Server version: 5.5.2-m2 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
解决办法:

复制代码 代码如下:
chown -R root /usr/local/mysql
chgrp -R mysql /usr/local/mysql
chown -R root /usr/local/mysql/bin
chgrp -R mysql /usr/local/mysql/bin
chgrp -R mysql /var/lib/mysql
chmod 777 /var/lib/mysql
chown -R root /var/lib/mysql/mysql
chgrp -R mysql /var/lib/mysql/mysql
chmod 777 /var/lib/mysql/mysql
chown -R root /var/lib/mysql/mysql/*
chgrp -R mysql /var/lib/mysql/mysql/*
chmod 777 /var/lib/mysql/mysql/*
chmod 777 /usr/local/mysql/lib/mysql/libmysqlclient.a

您可能感兴趣的文章:
php error Can't connect to local MySQL server...的解决方法
ERROR 2002 (HY000): Can't connect to local MySQL
Can't connect to local MySQL server through socket 问题的解决方法
mysql提示MySQL server has gone away导入时报错2006错误
[ERROR] Can't start server: can't create PID file: 问题的解决方法
Starting MySQL...The server quit without updating PID file的解决方法
MySQL-Proxy读写分离要注意的问题
nagios访问apache权限问题的解决方法
mysql Access denied for user 'root'@'localhost' 问题的解决方法
php读取txt文件组成SQL并插入数据库的方法

[关闭]