• Skip to primary navigation
  • Skip to content
  • Skip to primary sidebar
  • Skip to footer

The Geek Diary

HowTos | Basics | Concepts

  • Solaris 11
  • Solaris
    • SVM
    • ZFS
    • Zones
    • LDOMs
    • Hardware
  • Linux
    • CentOS/RHEL 7
    • RHCSA notes
    • SuSE Linux Enterprise
    • Linux Services
  • VxVM
  • VCS
  • Interview Questions
  • oracle
    • ASM
    • mysql
    • RAC
    • oracle 12c
    • Data Guard
  • DevOps
    • Docker
    • Shell Scripting

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. MySQL Error “Too many connections” and how to resolve it
  2. MySQL : how to set (change) user password
  3. How to backup and restore MySQL database
  4. MySQL Fails to Start Using systemctl On systemd Linux Distributions
  5. CentOS / RHEL 6 : How to Start/Stop MySQL Server (mysqld)

You May Also Like

Primary Sidebar

Recent Posts

  • How to use qperf to measure network bandwidth and latency performance in Linux
  • How to Password Protect GRUB2 in Oracle Enterprise Linux 7
  • How to move or rename a datafile in the same ASM diskgroup (Using ASM alias)
  • How to monitor Disk health with smartd (S.M.A.R.T.)
  • How To Check a Disk for Bad Blocks or Disk Errors on CentOS / RHEL

Footer

Cheat Sheets

  • LDOMs (OVM for SPARC) Command line reference
  • Solaris Volume Manager (SVM) command line reference
  • Solaris ZFS command line reference
  • RHEL 7 – RHCSA Notes (Cheat Sheets)
  • CentOS / RHEL 7 : firewalld Cheat Sheet
  • systemd command line reference (cheat sheet)

Solaris interview questions

  • The ultimate Solaris Volume Manager (SVM) interview questions
  • The ultimate Solaris zones (containers) interview questions
  • The ultimate Solaris networking interview questions
  • The ultimate ZFS interview questions
  • Archives
  • Contact Us
  • Copyright

© 2018 · The Geek Diary