手机
当前位置:查字典教程网 >编程开发 >mysql数据库 >php 不能连接数据库 php error Can't connect to local MySQL server
php 不能连接数据库 php error Can't connect to local MySQL server
摘要:测试的php文件运行后报错Can'tconnecttolocalMySQLserverthroughsocket'/tmp/mysql.so...

测试的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 不能连接数据库 php error Can't connect to local MySQL server】相关文章:

Can't connect to MySQL server的解决办法

ubuntu linux下使用Qt连接MySQL数据库的方法

Mysql 主从数据库同步(centos篇)

深入Mysql字符集设置[精华结合]

在MySQL中使用GTIDs复制协议和中断协议的教程

根据mysql慢日志监控SQL语句执行效率

去掉mysql连接时报警声音的方法

史上最全的MySQL备份方法

mysql中取系统当前时间,当前日期方便查询判定的代码

为何连接 MySQL 数据库失败频繁

精品推荐
分类导航