The operation of the MYSQL user

Source: Internet
Author: User

MYSQL User's authorization
Why authorize?
MySQL's default user is root, because root is too large, but also for security reasons, generally only in the management of the database, if you want to connect a MySQL database in the project, it is recommended to create a new user with less permissions
Role: Restrict which host the specified user can log on to, which database to access, and what permissions to a database.

一、创建用户    (mysql 不区分大小写)    命令格式: create user  "username"@"host" identified by "password";            --username   你将创建的用户名            --host       指定该用户可以在哪个主机上登陆,如果是本地用户则可以用localhost,如果想让该用户可以任意远程主机登陆,则可以使用通配符 “%”             --password   该用户的密码,密码可以为空,为空则代表用户不需要密码就可以登陆            下面写几种例子:                                        create user "china"@"192.168.8.128" identified by "123456";                                        create user "china"@"localhost" identified by "123456";                                        create user "china"@"%" identified by "123456";                                        create user "china"@"%" identified by "";                                        create user "china"@"%";

Ii. Delegation of authority

    命令的格式: grant privileges on dataname.tablename to "username"@"host" ;    --privileges      用户的权限,如 select   insert    update 等, 如果要授予所有权限的话就使用 all     --dataname.tablename   库.表名   指定该用户对哪个数据库的表有操作的权限,如果要授予该用户对所有数据库和表的相应操作权限则可用*表示, 如*.*    在客户端登陆时: mysql -h"服务端的IP"  -u"指定的用户"  -p"密码"    grant select,insert on db1.table1 to "china"@"localhost" ;    grant all on db1.table1 to "chian"@"localhost";注意:用以上名令授权的用户是没有授权的权限,让该用户拥有授权的权限,可以在后面加上  with grant option                    例子:grant all on db1.table1 to "china"@"localhost"  with grant option;

Third, set up and change the user password

命令格式: set password for "username"@"host" = password ("new password");  这是未登陆的用户                                         set password = password ("new password");

Iv. revoking the user's privileges

            命令格式: revoke privileges on db1.table1 from "username"@"host";            例子: revoke select on  *.*  from "china"@"%";            注意:  撤销权限后,用户名会保存下来,但若在撤销权限前把用户给删除了的话,那么用户的权限也会删除

V. Delete users

         命令格式: drop user  "username"@"host";

Appendix:
To view the user's permissions: Show grants for "username";

Permissions List:
Alter: Modifies tables and indexes.
Create: Creates a database and a table.
Delete: Deletes records that are already in the table.
Drop: Discards (deletes) the database and table.
Index: Create or discard indexes.
Insert: Inserts a new row into the table.
REFERENCE: Not used.
SELECT: Retrieves the records in the table.
UPDATE: Modifies an existing table record.
File: Reads or writes files on the server.
PROCESS: View the thread information that is being executed on the server or kill the thread.
RELOAD: Overloads the authorization table or empties the log, host cache, or table cache.
SHUTDOWN: Shut down the server.
All: All permissions, all privileges synonyms.
USAGE: Special "No Permissions" permission.
User accounts include both "username" and "host", which indicates where the user is allowed to access. [email protected] '% ' means any address, which can be omitted by default. can also be "[Email protected]%", "[email protected]%.abc.com" and so on. The database format is [email protected], which can be "test." "or". * ", which represents all tables of the test database, which represents all tables for all databases.
The clause "with GRANT OPTION" means that the user can assign permissions to other users

The operation of the MYSQL user

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.