Database Connection Probelm / Sqlstate[28000] [1045] Access Denied For User

Hi,

Spent quite some time to try to fix a connection problem following advice from older threads but can’t solve this.

I do get the Gii interface and I can connect to the database in terminal.

But when I try to create a model Yii throws this error:

CDbConnection failed to open the DB connection: SQLSTATE[28000] [1045] Access denied for user ‘tom’@‘localhost’ (using password: YES)

My settings are:

'db'=>array(


		'connectionString' => 'mysql:host=127.0.0.1;dbname=my_db',


		'class'=>'CDbConnection',


		'emulatePrepare' => true,


		'username' => 'tom',


		'password' => 'my_password',


		'charset' => 'utf8',


	),

If I try with localhost it gives me CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] No such file or directory

Thanks for any help!

You must have the user defined in MySQL’s user table:




CREATE USER 'tom'@'localhost' IDENTIFIED BY 'my_password';



Notice that ‘localhost’ is not the same as ‘127.0.0.1’; if you want to be able to login from anywhere use ‘%’ as the host address.

Thanks for the help! I did create a user using the same SQL:

CREATE USER ‘tom’@‘localhost’ IDENTIFIED BY ‘my_pass’;

GRANT ALL ON wmm_db.* To ‘tom’@‘127.0.0.1’ IDENTIFIED BY ‘my_pass’;

I did receive success messages for both commands. I then restarted apache with sudo apachectl restart.

I still get the same error:

CDbConnection failed to open the DB connection: SQLSTATE[28000] [1045] Access denied for user ‘tom’@‘localhost’ (using password: YES)

Could by problem have to do with using 127.0.0.1 instead of localhost?

If I do use localhost I get CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] No such file or directory.

Oddly, when I tried to restart Mysql using the preference pane, I got an internal error.

I was able to fix my problem. Since the fact that I could not turn off mysql server in the preference pane hinted at some mysql config issue I deleted mysql from my system (there is a good tutorial on lynda.com)

After removing xamp from my machine, restarting, reinstalling mysql and then using 127.0.0.1 instead of localhost in my main.php settings, things are finally up and running.