Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

How do I create a user and specify a password in one line:

I thought CREATE USER 'foo'@'2.2.2.2' IDENTIFIED BY 'bar'; would do it but apparently it doesn't.

Any thoughts? I'm on version 5.1.49 of MySQL.

share|improve this question
    
I am curious what you mean "apparently it doesn't"...your command should create the user (with only the ability to log on from 2.2.2.2 and no other privileges)...so why do you say it doesn't create it? –  Derek Downey Jan 7 '13 at 22:22

1 Answer 1

Your syntax is the good one :

[root@localhost] [(none)] mysql> CREATE USER 'foo'@'2.2.2.2' IDENTIFIED BY 'bar';
Query OK, 0 rows affected (0.00 sec)

You can see if your user is created by using :

[root@localhost] [(none)] mysql> show grants for 'foo'@'2.2.2.2';
+----------------------------------------------------------------------------------------------------------+
| Grants for foo@2.2.2.2                                                                                   |
+----------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'foo'@'2.2.2.2' IDENTIFIED BY PASSWORD '*E8D46CE25265E545D225A8A6F1BAF642FEBEE5CB' |
+----------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

But it'll work only if you connect from 2.2.2.2.

Max.

share|improve this answer
1  
you ... really didn't answer the question. –  jcolebrand Jan 5 '13 at 5:27
    
Oh really? Sorry about that! He asked for how to create a user with a password, i did. Next i gave my opinion on his 2.2.2.2 and finaly i asked him his exact problem... –  Maxime FOUILLEUL Jan 5 '13 at 9:04
    
clarification: How do I create a user and specify a password in one line: –  jcolebrand Jan 5 '13 at 9:05
2  
Ok, let's try again. The question states that he tried that, and it didn't let him use the password that he provided. Therefore, he's asking why it didn't work. It's entirely possible that he actually supplied 2.2.2.2, but I bet that's shorthand-example, just as foo and bar are. Maybe what you meant to do was to leave a comment on the question asking what the exact error is? –  jcolebrand Jan 5 '13 at 9:16
1  
I am going to give you a +1 for what you contributed because doing this in one command is not widely known unless one is fully aware of MySQL's non-ANSI shortcuts and caveats. As written, you answer does answer the question as posed in its context. –  RolandoMySQLDBA Jan 6 '13 at 5:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.