Summary of how to change the mysql user password

Source: Internet
Author: User

Summary 1. method 1: run the mysqladmin command. It is applicable to remembering the old root password. Modify the root password Syntax: www.2cto.com mysqladmin-u username-p old password new password. Example: # mysqladmin-u root-proot password mysql -- Note: if the old password is entered incorrectly, the following error will be reported # mysqladmin-u root-proot1 password mysqlmysqladmin: connect to server at 'localhost' failederror: 'Access denied for user 'root' @ 'localhost' (using password: YES) 'Method 2: directly update the password field in the user table -- applicable to removing the root password and duplicating the root password Set www.2cto.com Step 1: Modify MySQL Logon Settings # vi/etc/my. cnf -- windows system is my. INI file -- Add the following sentence to the [mysqld] section: skip-grant-tables. If the [mysqld] field is not found, you can manually add [mysqld] datadir =/var/lib/mysqlsocket =/var/lib/mysql. sockskip-name-resolveskip-grant-tables Step 2: restart mysql [root @ gc ~] # Service mysql restartShutting down MySQL .. [OK] Starting MySQL... [OK] Step 3: log on to and modify the MySQL root Password. At this time, you can directly use mysql to access the database without a password. [root @ gc ~] # MysqlWelcome 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 itsaffiliates. other names may be trademarks of their respectiveowners. type 'help; 'or' \ H' for help. type '\ C' to clear The current input statement. mysql> use mysql; Database changedmysql> 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 [root @ gc ~] will be reported when you log on with mysql directly. # MysqlERROR 1045 (28000): Access denied for user 'root' @ 'localhost' (using password: NO) Step 4: modify the MySQL Logon Settings and then delete/etc/my. skip-grant-tables Step 5 in the cnf file: restart mysql [root @ gc ~] # Service mysql restartShutting 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.