Add a user to MySQL

Source: Internet
Author: User

Command method. Note that each line is followed by one; indicates that a command statement ends.
Format: grant select on database. * To username @ login host identified by "password"

Example 1: Add a user named "test1" with the password "ABC" so that the user can log on to any host and have the permission to query, insert, modify, and delete all databases. First, use the root user to connectMySQLAnd then type the following command:
Grant select, insert, update, delete on *. * To test1 @ "%" identified by "ABC ";

However, the User Added in Example 1 is very dangerous. If you want someone to know the password of test1, then he can log on to your computer on the Internet.MySQLThe database can do whatever you want. For the solution, see Example 2.

Example 2: Add a user named "Test2" with the password "ABC" so that the user can only log on to localhost, you can also query, insert, modify, and delete the database mydb (localhost refers to the local host, that isMySQLIn this way, the user knows the password of Test2 and cannot directly access the database from the Internet.MySQLThe web page on the host is accessed.

Grant select, insert, update, delete on mydb. * To Test2 @ localhost identified by "ABC ";
If you do not want Test2 to have a password, you can run another command to remove the password.
Grant select, insert, update, delete on mydb. * To Test2 @ localhost identified "";

 

Related Article

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.