Adding a MySQL user via command line

There are times when you are stuck adding MySQL users via command line if this is one you are in luck.

On the machine MySQL is installed on run the following command. NOTE: there is no space between -p and ‘password’ and that ‘password’ is your password for root or the user you specify after -u.

CMD
mysql -h localhost -u root -ppassword

At the mysql> prompt enter the following commands. NOTE: In production you should replace ‘%’ with the ip or hostname you will be conecting from.

MySQL SQL
CREATE USER `magento`@'%' IDENTIFIED BY 'password';

Output should be:

Query OK, 0 rows affected (0.00 sec)

For a more thorough explanation of the CREATE USER syntax see: http://dev.mysql.com/doc/refman/5.0/en/create-user.html

Now to grant access…
Grant Access to all.. be careful if you execute this command you essentially adding a root user.

MySQL SQL
GRANT ALL ON *.* TO 'magento'@'%';

If you had a database named ‘magento’ you should change the command to look like..

MySQL SQL
GRANT ALL ON 'magento'.* TO 'magento'@'%';

To create a read only user…

MySQL SQL
GRANT SELECT ON 'magento'.* TO 'magento'@'%';

For a more thorough explanation of the GRANT syntax see: http://dev.mysql.com/doc/refman/5.0/en/grant.html

Any questions?

Comments (1)

  1. 14:32, 2011/12/18Multiplication Chart  / Reply

    i like it

Leave a Reply

Allowed Tags - You may use these HTML tags and attributes in your comment.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Pingbacks (0)

› No pingbacks yet.