The following article will guide you to create users and databases using MySQL via the command line (Terminal).
Join the channel Telegram of the AnonyViet 👉 Link 👈 |
MySQL Login
mysql -u root -p
Create a new database
create database tên_database_muốn_tạo ;
Create and assign permissions for users
create user 'tên_username'@'localhost' identified by 'password_muốn_tạo';
To change the user’s password, use the command:
set password for 'tên_username'@'localhost' = password('password_muốn_đổi');
Set all permissions for the user using the command:
grant all on tên_database.* to tên_username@localhost;
If you want to assign limited permissions to users, use the following command line:
grant SELECT on tên_database.* to tên_username@localhost;
Change the word SELECT with one of the following rights
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 MySQL command mode
exit
Here is the entire command to create a database, a user and assign user permissions to the database:
You can change the database name, user, password as you like
mysql -u root -p create database dq_website; create user duyquang@localhost; SET PASSWORD FOR duyquang@localhost= PASSWORD("123456"); GRANT ALL PRIVILEGES ON dq_website. * TO duyquang@localhost IDENTIFIED BY "123456"; FLUSH PRIVILEGES; exit;