User Management in MySQL

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.