How to create (add new) a MySQL user in command line

Question

When you are setting up your MySQL you need to create new users. Using the command line you can do it easily.

Answer

First create your database if it's not done yet. Then create your mysql user.

create database mynewdb;

What you need to replace:

A user who can access all tables in a given database

grant all privileges on mynewdb.* to 'user1'@'localhost' identified by "@s3cur3PWD";

A user who can access all databases

grant all privileges on *.* to 'user1'@'localhost' identified by "@s3cur3PWD";

A user who can access a given table in a given database

grant all privileges on mynewdb.some_table to 'user1'@'localhost' identified by "@s3cur3PWD";