How to create user and database in most Simplest way ?

chirag

Creating Mysql or MariaDB user and database in Linux (Centos 7 or Ubuntu) ?

Creating user and database is very simple but we need to follow commands very carefully. I will show you how to create user and database using terminal command.

How to Create user and encrypted with password ?

Using below command we can create user and also encrypt it with password. 

CREATE USER ‘newuser’@’localhost’ IDENTIFIED BY ‘password’;

How to Create Database under specific user. 

GRANT ALL PRIVILEGES ON * . * TO ‘newuser’@’localhost’;
FLUSH PRIVILEGES;

How To Grant Different User Permissions

GRANT [type of permission] ON [database name].[table name] TO ‘[username]’@’localhost’;

Example :- GRANT SELECT, INSERT, DELETE ON database.* TO ‘user’@’localhost’;

How to check user is created. Below command will list all the users.

SELECT User FROM mysql.user;

How to drop user ?

DROP USER ‘demo’@‘localhost’;

How to Drop Database ?

This command will delete the database if exists and will not prompt error message.
DROP DATABASE IF EXISTS tutorial_database;

How to check the Database ?

show databases;

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.