连接不到mysql,求指导。。。
这个是连接mysql的php页面代码<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
$mysql_host = 'localhost';
$mysql_user = 'root';
$mysql_password = '11111';
$mysql_database = 'tsinghua';
if (!mysql_connect($mysql_host, $mysql_user, $mysql_password)) {
die(mysql_error());
}
if (!mysql_select_db($mysql_database)) {
die(mysql_error());
}
?>
在本地能用root登录mysql,但是无法连接mysql,在web页面上报这样的错误:Access denied for user 'root'@'localhost' (using password: NO),那个代码明明写着mysql的密码呢,为何还是登不上去啊。。。要疯了 是不是mysql的权限给的不对啊,:em03::em03: 回复 1# qidunhu
GRANT ALL ON `tsinghua`.* TO 'root'@'%' IDENTIFIED BY "11111"; 你没有连接数据库 啊!
链接数据库: @mysql_connect("locahost","root","11111",1,131072) or die("对不起!数据库服务器连接失败");
选择数据库: mysql_select_db("tsinghua");
设置字符集:mysql_query("set names utf-8");
$mysql_host = 'localhost';
改成127.0.0.1试试。 mysql有毛病,换socketPath: '/var/run/mysqld/mysqld.sock', 按照4L的试试吧,我怀疑是括号里面的参数没有加双引号吧~~~
页:
[1]