php 不能连接数据库 php error Can't connect to local MySQL server
时间:2023-11-07 10:43:50
测试的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
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python机器学习包mlxtend的安装和配置详解
![](https://img.aspxhome.com/file/2023/3/135373_0s.png)
Python二进制文件读取并转换为浮点数详解
![](https://img.aspxhome.com/file/2023/0/77640_0s.png)
Webpack path与publicPath的区别详解
Python基于yaml文件配置logging日志过程解析
打包FlaskAdmin程序时关于static路径问题的解决
![](https://img.aspxhome.com/file/2023/6/59306_0s.png)
python hbase读取数据发送kafka的方法
初识python的numpy模块
Python Pygame实现俄罗斯方块
![](https://img.aspxhome.com/file/2023/8/77898_0s.jpg)
python多线程http压力测试脚本
用python画个敬业福字代码
![](https://img.aspxhome.com/file/2023/4/115194_0s.png)
教你使用Python的pygame模块实现拼图游戏
python的描述符(descriptor)、装饰器(property)造成的一个无限递归问题分享
MySQL跨服务器数据映射的实现
![](https://img.aspxhome.com/file/2023/4/67524_0s.png)
解决python写的windows服务不能启动的问题
解决Django响应JsonResponse返回json格式数据报错问题
Python利用Django如何写restful api接口详解
![](https://img.aspxhome.com/file/2023/0/98830_0s.jpg)
在python的类中动态添加属性与生成对象
pip安装提示Twisted错误问题(Python3.6.4安装Twisted错误)
![](https://img.aspxhome.com/file/2023/7/128447_0s.png)
Python实现在Excel文件中写入图表
![](https://img.aspxhome.com/file/2023/7/133907_0s.jpg)
MYSQL 表的全面总结
![](https://img.aspxhome.com/file/2023/2/70392_0s.png)