This article will guide you to create a database and user mysql with the terminal command.
Login to MySQL
mysql -u root -p
Create database
create database dbname;
Create and set permissions for users
create user 'username'@'localhost' identified by 'password';
To change the user password
set password for 'username'@'localhost' = password('password');
Set all permissions for user
grant all on dbname.* to username@localhost;
If you want to restrict user access, use the following command
grant SELECT on dbname.* to username@localhost; // SELECT permissions
The list of permissions you can set for the user
ALL
ALTER
CREATE VIEW
CREATE
DELETE
DROP
GRANT OPTION
INDEX
INSERT
SELECT
SHOW VIEW
TRIGGER
UPDATE
Reload all the privileges
FLUSH PRIVILEGES;
Exit
exit