How can I set a password for a user in a MySQL database?

Source: Internet
Author: User
Tags mysql insert

When you install MySQL on your machine for the first time, you can access the database anonymously or enter the database as a root without a password. If you are an administrator, you need to establish and authorize some users, which also involves setting the password. Next we will discuss how to set the password:

First, we should know that password storage in the Mysql database must be encrypted using the password () function. because the user table stores passwords in encrypted form, rather than plain text. if you are not encrypted, execute the following statement in the database:

      use mysql insert into user (host,user,password) values('%','user_name','your password'); flush privileges;

I believe that the results will not satisfy you. Because the server compares the encrypted values, the server connection will fail. here we need to describe flush privileges; this

Command to reload the authorization table. You can also use mysqladmin-u root reload or mysqladmin-u root flush-privileges in shell.

Implement the reload authorization table.

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")

The above two methods must be used to reload the authorization table.

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

Example:

     grant all on *.* to mailto:user_name@ identified by "your password";

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

Example:

      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.