0

I want to create a new mysql user and database demo in my company. Here is the commands i input in the mysql.exe :

create user 'admin'@'localhost' identified by 'admin';
create database dem;

Everytime i have that response:

access denied for user ''@'localhost' to database.

Actually i refered to that similar question :

Can anyone help please ???

Community
  • 1
  • 1
enzo
  • 301
  • 2
  • 5
  • 11
  • Under which user (if any) are you running mysql? And does that user have rights to create users and databases? – peterm May 01 '13 at 20:19

2 Answers2

0

I would suggest creating the database first then you can create a user, and use the GRANT option to allow permissions to that user for whatever you find necessary. However, creating a user first then a database while it's able to "potentially" work, isn't the best practice with MySQL. So you want to effectively do the Steps as such:

  1. Create Database
  2. Create User
  3. GRANT permissions
  4. ???
  5. Profit
Mentalproblemz
  • 20
  • 1
  • 1
  • 7
  • Thnx for your response. For each operation you suggested I have this response from the command line : "Access denied" OR "error in your SQL syntax" – enzo May 02 '13 at 07:34
0

You have to GRANT access to admin for dem.

GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' WITH GRANT OPTION;

You may have to also GRANT the same for admin@localhost as well. IIRC if you ever logon remotely with admin you would inherit the base privileges unless otherwise GRANTed

You can find many answers HERE.

apesa
  • 12,163
  • 6
  • 38
  • 43
  • thnx for your answer. I input the grant command this the error i got : "You have an error in your SQL syntax" – enzo May 02 '13 at 07:30
  • That's right out of the online MySQL reference. Look at my edits, that should execute now. That will work, but opens it up a little wide on security. Get beyond your issue here and then you can revist how to create and authorize users. I added a link to my answer. – apesa May 02 '13 at 14:21