Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+3 votes
4.6k views
in Q2A Core by

Can anyone tell me how to fix the following and what is the reason for this error ?

 

Warning: mysql_connect() [function.mysql-connect]: Access denied for user (using password: YES) in/answers/qa-include/qa-db.php on line 66


Could not establish database connection. Please check the username, password and hostname in the config file, and if necessary set up the appropriate MySQL user and privileges.

 

Q2A version: Latest version, just downloaded 7 days ago

3 Answers

+1 vote
by

me too..

/qa-include/qa-db.php on line 66

+3 votes
by

You write phenomenon, but don't write most important operation. I suppose it to be installation problem, and answer.

It is necessary to confirm lower installation documents well. Q2A instalation process is different from wordpress.

http://www.question2answer.org/install.php

You must edit qa-config.php by text-editor before installing.

define('QA_MYSQL_HOSTNAME', 'hostname');
define('QA_MYSQL_USERNAME', 'mysql-user');
define('QA_MYSQL_PASSWORD', 'mysql-password');
define('QA_MYSQL_DATABASE', 'mysql-database');
  • hostname: Your mysql server's host name or IP address. If MySQL is running on the same server as your website, the server host name is likely to be 127.0.0.1 or localhost.
    Probably you don't have to change this.
  • mysql-user: User name that can access mysql-database.
  • mysql-password: Password of mysql-user.

Of course it is necessary to make database and database user before installation.

by
Without the original poster supplying more information and if he has already configured the software how the installation guide states - this is the correct answer. Please make sure you supply more information in the future original poster.
+2 votes
by

Luckily, since you are working with an open source project, you have in your hands some capabilities to debug. I had your exact same error (at least the message), so I decided to do some debugging. Here are the steps you can try:

1. With the exact same information, can you connect to the DB with another type of client? I use the free DBVisualizer

2. On the same machine, write a small sample PHP file that tries to connect to the database. Your file could look like this:

<?PHP

$user_name = "mysql-user";
$password = "mysql-password";
$database = "mysql-db";
$server = "hostname";

$link = mysql_connect($server, $user_name, $password);

if ($link) {
        $db_found=mysql_select_db($database);

        if ($db_found) {
                print "Database Found "
                             print "Connection to the Server opened"
                             mysql_close();
        }
        else {
                print "Database NOT Found ";
                print mysql_error();
        }

}
else {
        print "Could not connect to server ";
        print mysql_error();
}
?>

3. Using this same test PHP file, can you connect to the MySQL database on a different server?

Using this method of debugging, you'll probably get a bit more information. Performing this, these were some of the problems I ran into:

  • I needed the MySQL plugin for PHP installed (this is done with sudo yum install php-mysqli on CentOS or RedHat based distros, or sudo apt-get install php5-mysql on Ubuntu).
  • I needed to set the bind-address attribute in the MySQL host's /etc/my.cnf (ex. bind-address=127.0.0.1)
  • Use a tool like PHP MyAdmin to try connecting to the same database. Try it from different hosts as well.
  • For some reason (I haven't been able to figure it out yet, but it's a workaround), I could not run question2answer on the same host as the one I was running MySQL on. I was fortunate to have two VM's, which are set up nearly identically, so on one VM, I have the MySQL server running, and on the other VM, I have question2answer/PHP/Linux/Apache installed, and I was able to connect to the database running on the first VM host.
 
...