Error 1044 <42000>: Access denied for user ''@' localhost' to database

NewbieDeveloper picture NewbieDeveloper · Jul 11, 2014 · Viewed 35.8k times · Source

I started learning PHP since last few days and this is where I'm stuck at.

When I try to type CREATE DATABASE blog; in shell, this is the error I get

'Error 1044 <42000>: Access denied for user ''@' localhost' to database'

How do I fix this?

I found titles to this error but those answer were complicated for me to understand.

Answer

Mainz007 picture Mainz007 · Jul 11, 2014

Entering mysql without a special user is not working. Or better to say: You enter the database, but the user you use then, has nearly no rights/priviliges. So in the beginning you need to login with your root account with mysql -u root -p. Then you can create your databases and work with them.

Hint 1: Never work with the root user in a productive system, but create an user, that just has access to one database.
Hint 2: Change the password of the root user as soon as possible with UPDATE user SET Password=PASSWORD('mein_pwd') WHERE user='root'; when you're in the database.