How to add new users and change passwords in mysql

Source: Internet
Author: User
Tags mysql host mysql tutorial

Add new users and change passwords in the mysql tutorial

Format: mysqladmin-u username-p old password New password

1. Add a password ab12 to the root user. First, enter the directory mysqlbin in dos, and then type the following command:

Mysqladmin-uroot-password ab12

Note: because the root account does not have a password at the beginning, the old-p password can be omitted.

2. Change the root password to djg345.

Mysqladmin-uroot-pab12 password djg345

7. Add new users. (Note: Unlike the above, the following commands in the mysql environment are followed by a semicolon as the command Terminator)

Format: grant select on Database tutorial. * 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 ";

However, the User Added in Example 1 is very dangerous. If someone knows the password of test1, then he can log on to your mysql database on any computer on the internet and do whatever he wants for your data. 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 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 by "";

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.