First, declare that, in general, you need to have the root permission in MySQL to modify the mysql password and grant permissions.
User: bkjia user database: bkjia.com
1. Create a user.
// Log on to MYSQL
@> Mysql-u root-p
@> Password
// Create a user
Mysql> insert into mysql. user (Host, User, Password) values ("localhost", "bkjia", password ("123456 "));
// Refresh the system permission list
Mysql> flush privileges;
In this way, a user named bkjia password 123456 is created.
Then log on.
Mysql> exit;
@> Mysql-u bkjia-p
@> Enter the password
Mysql> logon successful
2. Authorize the user.
// Log on to MYSQL (with ROOT permission ). I log on as ROOT.
@> Mysql-u root-p
@> Password
// Create a database for the user (bkjia.com)
Mysql> create database bkjia.com;
// Authorize the bkjia user to have all permissions on the bkjia.com database.
> Grant all privileges on bkjia.com. * to bkjia @ "%" identified by '20140901 ';
// Refresh the system permission list
Mysql> flush privileges;
Mysql> other operations
/*
If you want to assign some permissions to a user, you can write as follows:
Mysql> grant select, update on bkjia.com. * to bkjia @ "%" identified by '20140901 ';
// Refresh the system permission table.
Mysql> flush privileges;
*/
3. delete a user.
@> Mysql-u root-p
@> Password
Mysql> delete from user WHERE User = "bkjia" and Host = "localhost ";
Mysql> flush privileges;
// Delete the user's database
Mysql> drop database bkjia.com;
4. change the password of a specified user.
@> Mysql-u root-p
@> Password
Mysql> update mysql. user set password = password ('new password') where User = "bkjia" and Host = "% ";
Mysql> flush privileges;