ubuntu service 连不上Mysql
没有跳出错误提示
$con = mysql_connect("localhost","root","123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('buy',$con);
if (!$db_selected)
{
die ("Can\'t use test_db : " . mysql_error());
}
回复讨论(解决方案)
$con = mysql_connect("127.0.0.1","root","123"); 可以链接吗?很可能是权限问题。
你ubuntu怎么链接mysql的?
$ mysql -h localhost -u root -p; ?
"show grants" 看看返回什么?
“SELECT user, host FROM mysql.user” 又返回什么?
谢谢changjay,
用127.0.0.1 也是不行的,用服务器的公网ip也不行
$ mysql -h localhost -u root -p; 这个可以正常连接Mysql
Show grants 结果如下
Grants for root@localhost
GRANT ALL PRIVILEGES ON *.* TO 'ROOT' @ 'LOCALHOST' IDENTIFIED BY PASSWORD 'JLFSAFSFS.....' WITH GRANT OPTION
GRANT PROXY ON ''@'' TO 'ROOT' '@' LOCALHOST ' WITH GRANT OPTION
mysql的user表信息是这样的
user host
root 127.0.0.1
root : : 1
debian-sys-maint localhost
root localhost
root ubuntu
不行是指什么? 错误信息是?
php fatal error: call to undefined function mysql_connect()
发现忘记安装PHP5-MYSQL
apt-get install php5-mysql搞定