MySQL database and user creation

$mysql -u root -p

Log in to MySQL, enter password.


select user from mysql.user;

List existing users.


create user 'username'@'localhost' identified by 'user_password';

Create user, setting their password. User is restricted to log in from the local machine.


create database database_name;

Create the database.


grant all privileges on database_name.* to 'username'@'localhost';

Grant rights to the user for the database.