php 不克不及銜接數據庫 php error Can't connect to local MySQL server。本站提示廣大學習愛好者:(php 不克不及銜接數據庫 php error Can't connect to local MySQL server)文章只能為提供參考,不一定能成為您想要的結果。以下是php 不克不及銜接數據庫 php error Can't connect to local MySQL server正文
測試的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