MySQL Forget root password

Source: Internet
Author: User

Http://www.rackspace.com/knowledge_center/article/mysql-resetting-a-lost-mysql-root-password

Mysql-resetting a lost MySQL root password

The MySQL root password allows full access to the MySQL database and allows for all actions to be undertaken including CRE ating new users, new databases, setting access rules and so on.

Losing one can be a difficult issue to encounter. Luckily, resetting the root password was easy as long as you had sudo access to the Server.

Contents
    • 1 not the Server root user
    • 2 Stop MySQL
    • 3 Safe Mode
    • 4 Login
    • 5 Reset Password
    • 6 Restart
    • 7 Login

Not the Server root user

A Common issue is confusing the Server root user with the MySQL root user.

The server root user is the server ' s main user. The MySQL root user has all control over MySQL only. The ' root ' users is not connected on any.

Stop MySQL

The first thing to does is stop MySQL. If you are using Ubuntu or Debian, the command is as follows:

Sudo/etc/init.d/mysql stop

For CentOS, Fedora, and RHEL the command is:

Sudo/etc/init.d/mysqld stop

Safe mode

Next we need to start MySQL on safe mode-that is to say, we'll start MySQL but skip the user privileges table. Again, note that you'll need to has sudo access for these commands so you don't need to worry on any user being able To reset the MySQL root password:

sudo mysqld_safe--skip-grant-tables &

Note:the ampersand (&) at the end of the command is required.

Login

All we need to does now are to logs into MySQL and set the password.

Mysql-u Root

Note:no password is required on this stage as when we started MySQL we skipped the user privileges table.

Next, instruct MySQL which database to use:

Use MySQL;

Reset Password

Enter the new password for the root user as follows:

Update user set Password=password ("Mynewpassword") where user= ' root ';

And finally, flush the privileges:

Flush privileges;

Restart

Now the password have been reset, we need to restart MySQL by logging out:

Quit

and simply stopping and starting MySQL.

On Ubuntu and Debian:
Sudo/etc/init.d/mysql Stop...sudo/etc/init.d/mysql Start
On CentOS and Fedora and RHEL:
Sudo/etc/init.d/mysqld Stop...sudo/etc/init.d/mysql Start

Login

Test the new password by logging in:

Mysql-u root-p

You'll be prompted for your new password.

MySQL Forget root password

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.