mysql create a user and specify the database used by the new user

First we have to log in to the database with the root user
mysql -uroot -proot This is the root user -p followed by the password is root

First we have to create a new database
create DATABASE sb; we have created a database called sb

Again we create a new user

create user 'user name' @ 'host' identified by 'password'; for
example,
create user 'dsb' @ 'localhost' identified by 'wsdsb'; here a dsb user is created, the password is wsdsb, and the host is pointing to localhost

Authorization command: grant all privileges on database name. * To 'user name' @ 'host';

grant all privileges on sb. * to 'dsb' @ 'localhost'; users of dsb have all operation permissions on the database sb

The key point comes [effective command]: flush privileges; this is like a commit transaction in the database

You can use mysql -rdsb -pwsdsb when you open mysql again;

At this time, you will see that the database under this user is only sb, and this user cannot create a new database. You can add, delete, and check the table to see if it is very slippery.

Under normal circumstances, we will not give the root user to others, too dangerous

Published 3 original articles · Likes0 · Visits 140

Guess you like

Origin blog.csdn.net/small44444/article/details/105096400