LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   FEDORA /MYSQL Issue (https://www.linuxquestions.org/questions/linux-newbie-8/fedora-mysql-issue-608764/)

chaotix2003 12-23-2007 04:16 PM

FEDORA /MYSQL Issue
 
Hi All,

I have a virtual dedicated server hosted by godaddy and I seem to be having 'permission' issues connecting to mysql from a site hosted on the local server.
I have a script (db.php) on the local site that is suppose to connect the database but each time i run the script, the following error is displayed on the browser:

Could not connect to the database. Error = Access denied for user 'xMulch89'@'localhost' (using password: YES)

It does not matter wheather i use root or any other user, I still get the error message.I am able to log onto mysql as root or any user from bash /view tables/modify
I have also tried modifying the hosts.allow file but obviously that did not help. What am i doing wrong?

Please help:

Below is a copy of db.php file

<?php
$db_host = "localhost";
$db_user = "xMulch89";
$db_password = "xxxxxxx";
$db_name = "Webstore1";

$connect = mysql_connect("$db_host", "$db_user", '$db_password');
if ($connect){
echo "Congratulations!\n<br>";
echo "Successfully connected to MySQL database server.\n<br>";
}else{
$error = mysql_error();
echo "Could not connect to the database. Error = $error.\n<br>";
exit();
}

?>

btmiller 12-23-2007 04:25 PM

Can you login from mysql on the command line and execute the following:

Code:

use mysql
select user,host from user

This will print out the users and the hosts they're allowed to connect from. Do you see xMulch89 and localhost as a valid pair? If so try running:

Code:

select user,host,password from user
and make sure that the password hash for that user is set correctly. If it is, I would suggest looking at the MySQL log in /var/log to see if there are any error messages. You might also want to turn on verbose error logging in PHP as well (see this page for details).

chaotix2003 12-23-2007 05:49 PM

FEDORA /MYSQL Issue
 
Ok I have done the following as advised but I am still not getting anywhere

1. checked the user table in mysql and verified that the user xMulch89 is there and associated to localhost for database Webstore1 (All Privileges)
Deleted and recreated user

2. Nothing on mysql log

071223 14:03:43 mysqld started
071223 14:03:43 InnoDB: Started; log sequence number 0 43665
071223 14:03:43 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.0.45-log' socket: '/var/lib/mysql/mysql.sock' port: 3306 Source distribution
071223 14:36:24 [Note] /usr/libexec/mysqld: Normal shutdown

071223 14:36:24 InnoDB: Starting shutdown...
071223 14:36:27 InnoDB: Shutdown completed; log sequence number 0 43665
071223 14:36:27 [Note] /usr/libexec/mysqld: Shutdown complete

071223 14:36:27 mysqld ended

071223 14:36:47 mysqld started
071223 14:36:47 InnoDB: Started; log sequence number 0 43665
071223 14:36:47 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.0.45-log' socket: '/var/lib/mysql/mysql.sock' port: 3306 Source distribution

3. Php.ini error reporting set to: error_reporting = E_ALL & ~E_NOTICE | E_STRICT
Previously: error_reporting = E_ALL

chaotix2003 12-23-2007 06:58 PM

FEDORA /MYSQL Issue
 
Fixed!!

I finally figured it out - all in the syntax (missing the double quotes "" ).

<?php
$db_host = "localhost";
$db_user = "xMulch89";
$db_password = "xxxxxxx";
$db_name = "Webstore1";

$connect = mysql_connect("$db_host", "$db_user", '$db_password');
if ($connect){
echo "Congratulations!\n<br>";
echo "Successfully connected to MySQL database server.\n<br>";
}else{
$error = mysql_error();
echo "Could not connect to the database. Error = $error.\n<br>";
exit();
}

?>

btmiller 12-23-2007 10:57 PM

Aha ... that's right ... IIRC PHP will take a single quoted string literally, instead of substituting for the variable. Python's been my Web programming language of choice lately and I haven't done anything with PHP for a couple years, so I didn't catch that. I think it would also work with no quotes at all in this case.


All times are GMT -5. The time now is 11:52 PM.