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

Techgoeasy

Learn Oracle, PHP, HTML,CSS,Perl,UNIX shell scripts

  • Home
  • Oracle
    • Oracle database
    • Oracle Ebusiness Suite
    • Oracle weblogic
    • Oracle Performance Tuning
    • Oracle Hyperion
    • Oracle Cloud Tutorials
  • SQL
  • interview questions
  • Linux
  • PHP and HTML
  • Downloads
  • General
Home » Web development » mysql » How to reset MySQL root password on your Linux server

How to reset MySQL root password on your Linux server

December 19, 2021 by techgoeasy Leave a Comment

We may sometimes need to reset the MySQL root password on your Linux server. Here are the steps to do that

We need the root user privilege to do this

Step1 Login as root user and Stop the MySQL server

/etc/init.d/mysql stop
or
service mysql stop

Step 2 Start MySQL in safe mode and skip the use of the “grant tables”

/usr/bin/mysqld_safe --user=mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --datadir=/var/lib/mysql --skip-grant-tables --skip-networking &
or
/usr/bin/mysqld_safe --skip-grant-tables &

Step 3 Reset the MySQL root password

mysql -u root
use mysql;
update user set authentication_string=PASSWORD("newpass") where User='root';
flush privileges;

or

mysqladmin -u root flush-privileges password newpass

or

mysql -u root
use mysql;
SET PASSWORD FOR [email protected]'localhost' = PASSWORD('newpass');
flush privileges;

Step 4 Stop the MySQL service running in safe mode

kill `cat /var/run/mysqld/mysqld.pid`

or

/etc/init.d/mysql stop

or

/etc/init.d/mysqld stop

Step 5 Start the Mysql service

/etc/init.d/mysql start 
or 
service mysql start
or
/etc/init.d/mysqld start

Step 6 login with the new password

mysql -u root -p

Related Articles

MySQL queries
MySQL COALESCE and NULLIF Function
How to start and stop mysql on Linux

Filed Under: mysql, Web development

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar



Subscribe to our mailing list

Enter your email address to subscribe to this blog and receive notifications of new posts by email

Recent Posts

  • Oracle tkprof utility
  • What is Skew in Database?
  • how to find file based on size in linux
  • SQL trace, 10046 event in Oracle
  • How to use sed replace string in file

Copyright © 2023 : TechGoEasy

  • Hire me
  • Privacy Policy
  • Contact Us
  • New? Start Here
  • About Us