1

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.

Udhav Sarvaiya
  • 9,380
  • 13
  • 53
  • 64
NewbieDeveloper
  • 126
  • 2
  • 2
  • 10
  • 1
    Please give an update with a closer description of what you are doing. With what user are you logged in? At which point do you try to create the database? – Mainz007 Jul 11 '14 at 08:40
  • I'm watching the tutorial and following exactly what he's been doing. I first opened the shell, then enter 'mysql' and enter. After that I tried to check databases, so I did 'SHOW DATABASES' and it did showed but there was 8 databases but it shows only 2 in shell. It didn't even showed the one I did manually in phpmyadmin. Then I tried to create a new database with 'CREATE DATABASE blog;' command. Sorry if I'm confusing you with my bad english – NewbieDeveloper Jul 11 '14 at 08:44
  • Is the tutorial online? Seems like you log in with the wrong user... – Mainz007 Jul 11 '14 at 08:47
  • wow. Thank you so much for the hint, after reading your comment instead of just entering 'mysql', I tried to enter 'mysql -u root -p' and it did fix my problem. Thank you so much bro :D – NewbieDeveloper Jul 11 '14 at 09:00

1 Answers1

4

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.

Mainz007
  • 533
  • 5
  • 16