Error 1044 <42000>: Access denied for user '&#

2020-04-20 08:46发布

问题:

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.

回答1:

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.