首页 > 数据库 > MySQL > 正文

php 不能连接数据库 php error Can't connect to local MySQL server

2024-07-24 12:44:27
字体:
来源:转载
供稿:网友
测试的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

您可能感兴趣的文章:

VS2015自带LocalDB数据库用法详解完美解决MySQL通过localhost无法连接数据库的问题sql server连接不上怎么办 SQL Server2008R无法登录的解决方案(1814/18456)图文详解Windows Server2012 R2中安装SQL Server2008解决SQL Server 2008 不能使用 “.” local本地连接数据库问题
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表