Due to the need for work, to create a new MySQL user, after reviewing the MySQL manual, did the following methods to record.
#新增一个mysql用户custom, the password is obscure and can only be accessed and manipulated from the local database test
GRANT Select,insert,update,delete,create,drop on test.* to ' custom ' @ ' localhost '
Identified by ' obscure ';
#执行完成后会发现user表中多了一条记录, there is one more record in the DB table, and the permissions are written to the DB table.
GRANT all privileges on * * to ' mysql1 ' @ ' localhost ' identified by ' 123456 ' with GRANT OPTION;
#直接操作user表, add a new user
#insert语句在user表中插入记录, allow user custom to connect from host localhost with password 1234,
#但不授予全局权限 (all permissions are set to Default ' N ')
INSERT into Mysql.user (Host,user,password) VALUES (' localhost ', ' mysql1 ', Password (' 1234 '));
INSERT into Mysql.db (HOST,DB,USER,SELECT_PRIV,INSERT_PRIV,UPDATE_PRIV,DELETE_PRIV,CREATE_PRIV,DROP_PRIV)
VALUES (' localhost ', ' test ', ' mysql1 ', ' y ', ' y ', ' y ', ' y ', ' y ', ' y ');
#通常若直接修改授权表, you should tell the server to rename the authorization table with the flush privileges, which is the permission modification takes effect
FLUSH privileges;
#删除mysql的用户
DROP USER ' mysql1 ' @ ' localhost ';
#为安装后的最初用户root设置密码
Mysqladmin-u user_name-h host_name password ' newpwd ';
Mysql>set Password=password (' newpwd ');
#在全局级别使用grant usage statement (in *. *) to specify a password for an account without affecting the account's current permissions
Mysql>grant USAGE on * * to ' root ' @ ' localhost ' identified by ' 123456 ';
#还可已直接操作表user
UPDATE user SET Password=password (' 123456 ') WHERE host= "localhost" and user= "root";
FLUSH privileges;
This article from "Luther season" blog, declined reprint!