php不能连接数据库phperrorCan'tconnecttolocalMySQLserver

在夕阳西下时,伴着如夜晚霞,刮起来美丽的秋风,金黄的叶子从树上落下来,像一只只美丽的蝴蝶,翩翩起舞格外美丽。树下,一个个活泼可爱的小朋友正在捡树叶,放在收集本子里,把美丽的秋天永远珍藏。
测试的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不能连接数据库phperrorCan'tconnecttolocalMySQLserver就介绍到这了。人性最可怜的就是:我们总是梦想着天边的一座奇妙的玫瑰园,而不去欣赏今天就开在我们窗口的玫瑰.更多相关php不能连接数据库phperrorCan'tconnecttolocalMySQLserver内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!

标签: 连接数据库 php