sts
(Stephan Schindler)
December 26, 2013, 4:25pm
1
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!
JFReyes
(Jose Reyes)
December 26, 2013, 4:36pm
2
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.
sts
(Stephan Schindler)
December 27, 2013, 4:32pm
3
JFReyes:
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.
sts
(Stephan Schindler)
December 28, 2013, 3:40pm
4
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.