How to modify the MySQL user (root) password under Linux

Source: Internet
Author: User
Tags root access pkill

Below to share under Linux How to modify the MySQL user (root) password, in two cases: the first when the original MySQL root password, the second case to forget the original MySQL root password.

The modified users are listed as root.

First, the root of the original MySQL password;

Method One:

Outside the MySQL system, use the Mysqladmin

Copy CodeThe code is as follows:
# mysqladmin-u root-p Password "test123"

Enter Password: "Enter the original password"


Method Two:

By logging into the MySQL system,

?
1234567891011 # mysql -uroot -pEnter password: 【输入原来的密码】 mysql>use mysql; mysql> update user set password=passworD("test") where user=‘root‘; mysql> flush privileges;mysql> exit;


Second, forget the original MySQL root password;

First, you must have root access to the operating system. If you do not have the root authority of the system, consider the root system before taking the following steps.

Similar to Safe Mode login system, it was suggested that Pkill MySQL, but I do not recommend ha. Because when you execute this command, it can result in a situation like this:

Copy CodeThe code is as follows:
/ETC/INIT.D/MYSQLD status
Mysqld dead but Subsys locked

So even if you are in Safe mode to start MySQL may not be useful, so generally so/etc/init.d/mysqld stop, if you unfortunate first use Pkill, then start a bit stop.

Copy CodeThe code is as follows:
# Mysqld_safe--skip-grant-tables &

&, that means running in the background, no longer running in the background, then open a terminal.

Copy CodeThe code is as follows:
# MySQL
mysql> use MySQL;
mysql> UPDATE user SET Password=password ("test123") WHERE user= ' root ';
mysql> flush Privileges;
Mysql> exit;

How to modify the MySQL user (root) password under Linux

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.