MySQL forgot password solution in Linux

Source: Internet
Author: User
Tags mysql in

1. Close the MySQL service, see many of the online said to use this command/etc/init.d/mysqld restart, but I did not find mysqld file in the Init.d folder, so in the execution of this command has been an error, and then replaced by sudo Service MySQL stop to close MySQL services successfully

2. Start MySQL in Safe mode view online There are two ways to say it. The first is to use the command directly

Mysqld_safe--skip-grant-tables &

But I also gave an error when I used this command.

Second method (possible), modify the MySQL configuration file

# VI/ETC/MY.CNF
Add a sentence to the paragraph in [mysqld]: Skip-grant-tables
For example:
[Mysqld]
Datadir=/var/lib/mysql
Socket=/var/lib/mysql/mysql.sock
Skip-grant-tables

3. Start the MySQL service

The command I used was: sudo service MySQL start

4. Change the root user password

At this point you can log into the data directly in MySQL using the command line, or you can use the tool navicat

Using the Navicat tool is more convenient, I use the tool directly

配置好上面的数据连接,密码框中不用填写。
进入数据库后,打开mysql数据库查看user表中的数据


查看你的root账户的密码存的字段名称
在网上很多用的都是
UPDATE User SET = ' New-password ' WHERE User = ' Root '

 这个sql语句,但是我发现我的密码存的不是Password字段中,所以最开始执行这个语句的时候一直都失败,打开表中一看这个密码是存在
authentication_string 字段中的,所以执行的sql语句换成
UPDATE 'userset authentication_string=PASSWORD (' own password ')  where 'user'='root'  

The password () in this statement is an encryption method of the data.

5. Remove the skip-grant-tables in the MySQL configuration of the second step (be sure to go, or let all the people without the password can directly into the database), restore to the original appearance.

6. Restart the MySQL service with the command: sudo service mysql restart

 

MySQL forgot password solution in 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.