Error connecting to MySQL from PHP
I am new to PHP and MySQL.
In case of entering into MySQL if I enter the following command Code:
>$ mysql -h host_name -u user_name -p The problem is that if I enter the same from PHP with the following command : Code:
$link=mysql_connect ('host_name', 'user_name', 'password') OR die('ERROR : ' .mysql_error()) Quote:
Regards anindyanuri |
Does /var/lib/mysql/mysql.sock exist?
|
Hello!
Have you compiled your PHP wright? Look where you have your mysql.sock Code:
$ mysql -h host_name -u user_name -p Code:
./configure ... --with-mysql-sock=/tmp/mysql.sock --with-mysql=/path/to/mysql_directory/ PHP Code:
Hope this helped! Boby |
Try 127.0.0.1 instead of localhost for the hostname. Then what happens?
|
If the socket location is the problem as Boby suggests, instead of recompiling php you could:
a. edit the "mysql.default_socket =" line in php.ini or b. create a symlink from /tmp/mysql.sock to /var/lib/mysql/mysql.sock |
Quote:
Code:
$ ls -l /var/lib/mysql/ anindyanuri |
Quote:
The mysql.sock exists in /var/lib/mysql/ Checked this status, and the result is... Code:
mysql> status Quote:
Quote:
Code:
mysql Regards anindyanuri |
Quote:
Code:
Access denied for user: 'anindya@localhost.localdomain' (Using password: YES) Regards anindyanuri |
Quote:
Code:
; Default socket name for local MySQL connects. If empty, uses the built-in Quote:
Regards anindyanuri |
Ok, you shouldn't need that symlink as the socket is already in the right place, and works for your mysql client program, just not PHP.
The socket worked for the client app but not PHP, and the tcp/ip connection worked for PHP but was told by MySQL that the user was not permitted from that hostname. So you seem to have a problem with PHP for the socket, and maybe MySQL for the 127.0.0.1 route. Have all apps been installed from precompiled official .rpm files? Are there any updates for FC3 regards these apps? |
Quote:
|
Some improvement is there.................
If I write : Code:
$link = mysql_connect('127.0.0.1', 'user_name', 'password') Code:
$link = mysql_connect('127.0.0.1','','') Still I get error if I want to connect the databases which I have created with my own 'user_name' and 'password'. What is the problem? Why I cannot connect with my 'user_name' and 'password'? It is to be mentioned that my 'user_name' and 'password' is already granted for all privileges. Please help Anindyanuri |
Case - I
I am giving the output of 'netstat -anl' command while I am connected to mysql as user 'anindya' and host 'localhost': Porto RefCnt Flags Type State I-Node Path Unix 2 [ACC] STREAM LISTENING 8016 /var/lib/mysql/mysql.sock Unix 3 [ ] STREAM CONNECTED 14886 /var/lib/mysql/mysql.sock Case - II This is the output of the 'netstat -anl' command whicle I am connected to mysql as admin Porto RefCnt Flags Type State I-Node Path Unix 2 [ACC] STREAM LISTENING 8016 /var/lib/mysql/mysql.sock Unix 3 [ ] STREAM CONNECTED 26733 /var/lib/mysql/mysql.sock In second case I can able to connect to mysql from PHP but in Case-I, myself fails to connect to mysql from php. What to do? Regards |
hey
looks like selinux is enabled for http and mysql follow this thread http://drupal.org/node/14874 http://forums.mysql.com/read.php?11,...1482#msg-21482 regards |
Read those articles. The problem is exactly same which I am facing. Thank you Masand for your pin-point accuracy. I shall now try for the solutions, hope it will work. I'll inform what happens for me.
Regards anindyanuri |
All times are GMT -5. The time now is 02:28 PM. |