1

I am new install centos6.2.

in ssh part, I could access mysql with:

>mysql -u root -p
>se659;m

then I could see

mysql>

and I could use any mysql command like: show databases;, show columns from tableName,etc.

But when I use php code to connect mysql,

<?php
$handle_db = mysql_connect("localhost","root","se659;m") 
or die("can not connect Mysql Server");
?>

it shows can not connect Mysql Server

I use phpinfo() I could see enter image description here

and I install mysql in usr/local/mysql

Where is the problem? i feel puzzle #_@

cj333
  • 109
  • 11

1 Answers1

1

There are multilpe variables at work here.

  1. You have a custom installation of mysql in /usr/local/mysql. This means that your mysql socket may not be in the default location that PHP expects it to be. To fix this problem, make sure that mysql and PHP agree on the location of the socket. you could also use the network socket. The Mysql config might be in /usr/local/mysql/etc/my.cnf
  2. If you want to use a network (non local socket) connection, then Mysql must by configured to allow for network conenctions.
  3. Mysql uses the username and host for permissions checking. this means that "root@localhost" and "root@myhostname" are different "users" to mysql. Both root users must have a password, and have permissions for things to work.
  4. You might need to use mysqli_connect. MySQL 4 and 5 had different password hash types, which made them incompatible. PHP must use the password hash that Mysql expects. This might be solved by myqli_connect.
edgester
  • 583
  • 1
  • 5
  • 15