• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Geek Diary

CONCEPTS | BASICS | HOWTO

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • Linux Services
    • VCS
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
    • Data Guard
  • DevOps
    • Docker
    • Shell Scripting
  • Interview Questions
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to reset MySQL database root password

By admin

Question: I forgot the MySQL root password. How do I reset it?

# mysql -u root
Access denied for user 'root'@'localhost' (using password: NO)'

Solution:

The MySQL root password can be set using the following procedure:

1. Stop the MySQL service:

# service mysqld stop
Stopping MySQL:                                            [  OK  ]

2. Start MySQL in safe mode as it does not ask for root password in safe mode.

# /usr/bin/mysqld_safe --skip-grant-tables &
Note: mysql_safe is a shell script which invokes mysqld, but additionally traps any forceful terminations of the MySQL server and avoids any database corruption.

3. Change the password of the root user:

# mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('new_password') WHERE user='root';
mysql> FLUSH PRIVILEGES;
mysql> exit;

4. Restart mysqld using mysqladmin to ensure that the service shuts down successfully (as it was started manually in step 2).

# mysqladmin -p shutdown

5. Restart the MySQL service as per normal:

# service mysqld start

Filed Under: mysql

Some more articles you might also be interested in …

  1. Understanding the REVOKE statement in MySQL
  2. MySQL Error “Too many connections” and how to resolve it
  3. Multi-Versioning in MySQL Database
  4. Understanding MySQL Query Cache
  5. How to Configure Multiple MySQL Servers On One System Using mysqld_multi
  6. How to List and Set SELinux Context for MySQL Server
  7. “expect” script to provide password to mysql_config_editor
  8. Beginners Guide to Implementing Table Maintenance in MySQL
  9. How to obtain MySQL metadata (metadata access methods)
  10. How to Restore a Specific Database or Table (MySQL)

You May Also Like

Primary Sidebar

Recent Posts

  • How to disable ACPI in CentOS/RHEL 7
  • How to Use real-time query to access data on a physical standby database
  • CentOS/RHEL 8: “ACPI MEMORY OR I/O RESET_REG” Server Hung after reboot
  • How to Create a Physical Standby Database by Using SQL and RMAN Commands
  • Archives
  • Contact Us
  • Copyright

© 2021 · The Geek Diary