How to set a password for a user under the MySQL database

Source: Internet
Author: User
Tags flush mysql database

When MySQL is first installed on the machine, you can access the database anonymously or as root without a password. Also, if you are an administrator, you need to build and authorize some users, which involves setting up a password. Here's how to set a password:

First we should know that the password store in the MySQL database must be encrypted with the password () function. Because passwords are stored in encrypted form in the user table, not as plain text. If you do not encrypt, execute the following statement directly in the database:

Use MySQL

Insert into User (Host,user,password) values ('% ', ' user_name ', ' your password ');

Flush privileges;

I believe the result will not satisfy you. Because the server is comparing encrypted values, the server connection must fail. Here is the flush privileges; This command reloads the authorization table. You can also use mysqladmin-u root directly under the shell. Reload or mysqladmin-u root flush-privileges to implement overloaded authorization tables.

In the MySQL environment, you can use the following statement to set the password:

1.insert into User (Host,user,password) values ('% ', ' user_name ', password ("Your password");

2.set password for user_name = password ("Your password")

Both of these methods must be overloaded with authorization tables.

3. Of course, you can also set the password directly when creating a user, and the grant statement will automatically encrypt the password for you.

such as: Grant all on *.* to user_name@% identified by "Your password";

In addition, you can use the Mysqladmin program to set the password in the shell environment.

such as: mysqladmin-u root password "Your password"

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.