create database and new user in mysql with ssh

I keep forgetting how to do this. So, I will log it here once and for all:

Log into mysql:

mysql -u root -p

Create a database:

create database name_of_database;

Create a new user:

CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';

Give new user all the priviliges:

GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';

If you want to give the new user permission only for one database then the command is:

GRANT ALL PRIVILEGES ON name_of_database.* TO 'newuser'@'localhost';

Reload Mysql:


To change the password of the user:

mysqladmin -u root -p'oldpassword' password newpassword

Leave a Reply

Your email address will not be published. Required fields are marked *