How to create user and grant access to database in MySQL

Here is the sample about how to create a MySQL user and grant access to the database. In this example I use mysql command line tool.

First, let’s create a MySQL user:

  CREATE USER 'user_name'@'%' IDENTIFIED BY 'user_password';

After creating a database user let’s grant access to the database for the created user, so that the user can have all rights on the database:

  GRANT ALL PRIVILEGES ON mydatabase.* TO 'user_name'@'%';

More info about creating and granting access in MySQL here http://dev.mysql.com/doc/refman/5.5/en/adding-users.html