MySQL database creation user

Source: Internet
Author: User
Tags mysql host
For personal lessons, when adding a MySQL account, you must quote the username and host (local and %). Otherwise, the command is wrong.
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 connect to MySQL, and then type the following command:
Grant select, insert, update, delete on *. * to "test1" @ "%" identified by "ABC ";
Add all permission statements:
Run the following command in Example 1: Select, insert ,....) changed to "all privileges", which indicates that all permissions are granted, including database creation permissions and database deletion permissions, and are no longer limited to operations in one database.
Grant all privileges on *. * To 'root' @ '% 'identified by '123 ';
In example 1 (not supplemented), it is very dangerous to add users because your host is %, % Represents the host at any location, and local represents the meaning of "local". If, if someone wants to know the password of test1, he can connect to your MySQL database on any computer on the Internet and do whatever he wants for your data. For the solution, see Example 2.
According to the supplementary statement in Example 1, this statement should not be used on the MySQL server. If your server is hosted or remote, if you need to remotely manage the MySQL server, if you do not want to log on to the server through a Super Terminal, you have to use this statement. But you need to be clear that you can use this method to connect to the server, and other users can, so keep your MySQL password safe.
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 is, the host where the MySQL database is located), so that the user knows the password of Test2, he cannot access the database directly from the Internet, but can only access the database through the web pages on the MySQL host.
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 "";
Grant select, insert, update, delete on Dez. * to "Test2" @ "%" identified by "123456 ";
This article from: the foot home (www.jb51.net) detailed source reference: http://www.jb51.net/article/10484.htm

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.