Tạo mysql database và user bằng lệnh terminal

Bài viết này sẽ hướng dẫn tạo database và user mysql bằng lệnh terminal.

Đăng nhập MySQL

mysql -u root -p

Tạo database

create database dbname;

Tạo và thiết lập quyền cho user

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

Để thay đổi password user

set password for 'username'@'localhost' = password('password');

Thiết lập tất cả quyền cho user

grant all on dbname.* to username@localhost;

Nếu bạn muốn giới hạn quyền cho user thì dùng dòng lệnh sau

grant SELECT on dbname.* to username@localhost; // SELECT là quyền

Danh sách các quyền bạn có thể thiết lập cho user

ALL

ALTER

CREATE VIEW

CREATE

DELETE

DROP

GRANT OPTION

INDEX

INSERT

SELECT

SHOW VIEW

TRIGGER

UPDATE

Reload all the privileges

FLUSH PRIVILEGES;

Thoát

exit

Leave a Reply