How to change the mysql user password

Source: Internet
Author: User
Welcome to the Linux community forum and interact with 2 million technical staff to enter the methods for modifying the mysql user password. Summary 1. method 1: run the mysqladmin command to change the root password. The command is applicable to remembering the old root password and modifying the root password Syntax: mysqladmin-u username-p old password new password example: # mysqladmin-uroot

Welcome to the Linux community forum and interact with 2 million technical staff> go to the mysql user password modification method Summary 1. method 1: run the mysqladmin command to change the root password. It is applicable to remembering the old root password and modifying the root password Syntax: mysqladmin-u username-p old password new password example: # mysqladmin-u root

Welcome to the Linux community forum and interact with 2 million technicians>

Summary of how to change the mysql user password

1. Modify the root password

Method 1: Use the mysqladmin command

-- Applies to remembering the old root password and modifying the root password

Syntax:

Mysqladmin-u username-p old password New password

For example:

# Mysqladmin-u root-proot password mysql

-- Note: if the old password is incorrectly entered, the following error will be reported:

# Mysqladmin-u root-proot1 password mysql

Mysqladmin: connect to server at 'localhost' failed

Error: 'Access denied for user' root' @ 'localhost' (using password: YES )'

Method 2: directly update the password field of the user table

-- Applies to Resetting the root password when you forget the root password.

  

Step 1: Modify MySQL Logon Settings

# Vi/etc/my. cnf

-- Windows is my. ini file

-- Add skip-grant-tables in the [mysqld] section. If the [mysqld] field is not found, add it manually.

[Mysqld]

Datadir =/var/lib/mysql

Socket =/var/lib/mysql. sock

Skip-name-resolve

Skip-grant-tables

Step 2: restart mysql

[Root @ gc ~] # Service mysql restart

Shutting down MySQL... [OK]

Starting MySQL... [OK]

Step 3: log on to and modify the MySQL root Password

-- In this case, you can directly use mysql to access the database without a password.

[Root @ gc ~] # Mysql

Welcome to the MySQL monitor. Commands end with; or \ g.

Your MySQL connection id is 2

Server version: 5.5.24 MySQL Community Server (GPL)

Copyright (c) 2000,201 1, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

Affiliates. Other names may be trademarks of their respective

Owners.

Type 'help; 'or' \ H' for help. type' \ C' to clear the current input statement.

Mysql> use mysql;

Database changed

Mysql> update user set password = password ('new _ password') where user = 'root ';

Query OK, 5 rows affected (0.00 sec)

Rows matched: 5 Changed: 5 Warnings: 0

Mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

-- Note: If Step 1 is not performed, the following error will be reported when you log on to mysql directly.

[Root @ gc ~] # Mysql

ERROR 1045 (28000): Access denied for user 'root' @ 'localhost' (using password: NO)

Step 4: Modify the MySQL Logon Settings

Delete the skip-grant-tables in the/etc/my. cnf file.

Step 5: restart mysql

[Root @ gc ~] # Service mysql restart

Shutting down MySQL... [OK]

Starting MySQL... [OK]

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.