[MySQL] Three ways to assign a password to the root account

Source: Internet
Author: User
Tags mysql login

Preface: The previous period of time after the installation of MySQL has not control it, at that time in the strange why MySQL login do not password, the original has been used in the Super User account login (referred to as super users)

In fact, only blame themselves too ignorant, have been using the phpbydamin for the database of visual management, where to know so detailed?

The original source of this article MySQL official document 5.1

Text: Start with select User.password from mysql.user to query the password of the MySQL database root account

You can assign a password to the root account in several ways. Three ways are described below:

· Using the Set Password statement

· Using the mysqladmin command-line client program

· Using the UPDATE statement

To specify a password using Set password, connect to the server with root and execute two set password statements. Be sure to use the password () function to encrypt the password.

Statements in Windows:

Mysql-u Root
SET PASSWORD for ' root ' @ ' localhost ' = PASSWORD ('newpwd');
SET PASSWORD for ' root ' @ '% ' = PASSWORD ('newpwd');

Statements in Unix:

Mysql-u Root
SET PASSWORD for ' root ' @ ' localhost ' = PASSWORD ('newpwd');
SET PASSWORD for ' root ' @ 'host_name' = PASSWORD ('newpwd');

Replace the host_namein the second set password statement with the server host name. This is the hostname of the password you specified for the anonymous account.

To use mysqladmin to specify a password for the root account, execute the following command:

mysqladmin -u root password "newpwd"
mysqladmin host_name Password "newpwd"

The above commands apply to Windows and UNIX. Replace the host_namein the second command with the server host name. You don't need to enclose the password in double quotation marks, but you need to enclose it in double quotation marks if the password contains spaces or other characters dedicated to command interpretation.

You can also modify the user table directly using update. The following UPDATE statement can specify a password for two root accounts at the same time:

Mysql-u Root
UPDATE mysql.user SET Password = Password ('newpwd')
WHERE User = ' root ';
FLUSH privileges;

The UPDATE statement applies to Windows and UNIX.

After you set the password, you must provide the appropriate password when you connect to the server. For example, if you want to shut down the server with mysqladmin , you can use the following command:

Mysqladmin-u root-p shutdown
(Enter root password here)

[MySQL] Three ways to assign a password to the root account

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.