How to create Mysql database and user with terminal command

This article will guide you to create a database and user mysql with the terminal command.

Creat Mysql with 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

About us: admin

Leave a Reply

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