程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> 關於MYSQL數據庫 >> php 不能連接數據庫 php error Cant connect to local MySQL server

php 不能連接數據庫 php error Cant connect to local MySQL server

編輯:關於MYSQL數據庫
測試的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
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved