Home > Database > Mysql Tutorial > php 不能连接数据库 php error Can't connect to local_MySQL

php 不能连接数据库 php error Can't connect to local_MySQL

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-01 13:51:44
Original
1364 people have browsed it

测试的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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template