Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

Recover/Replace MySQL Root Password – UNIX

Posted on November 19, 2015December 30, 2016 By David Kittell

Forgetting or never having the root password for a MySQL database can be rather difficult if it is now your job to support it.

Note: You will need root access on the UNIX box to follow these commands.

# Debian / Ubuntu
sudo /etc/init.d/mysql stop

# CentOS / Red Hat
sudo /bin/systemctl stop mariadb
#sudo /bin/systemctl stop mysql
mysqld_safe --skip-grant-tables &
mysql -u root
use mysql;
update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
flush privileges;
quit
# Debian / Ubuntu
sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start

# CentOS / Red Hat
sudo /bin/systemctl stop mariadb
#sudo /bin/systemctl stop mysql
sudo /bin/systemctl start mariadb
#sudo /bin/systemctl start mysql

If for some reason you get an error saying mysql database doesn’t exist you may need to remove mysql/mariadb configuration files (/etc/my.cnf /etc/my.cnf.d/) or reinstall. Understand that that if you do that you may loose some or all data.

Originally Posted on November 19, 2015
Last Updated on December 30, 2016
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code MySQL SQL UNIX Shell Scripts

Post navigation

Previous post
Next post

Related Posts

Format Date Function

Posted on July 31, 2013October 26, 2015

IF OBJECT_ID(N’dbo.fnFormatDate’) IS NOT NULL DROP FUNCTION dbo.fnFormatDate GO CREATE FUNCTION dbo.fnFormatDate ( @MyDate DATETIME ,@Format NVARCHAR(50) ,@LANGUAGE INT = NULL ) RETURNS NVARCHAR(255) AS BEGIN /* SELECT dbo.fnFormatDate(GetDate(), ‘MMMM DDDD DD, YYYY HH:NN:SS AMPM’, NULL) –October Friday 03, 2013 00:13:28 PM SELECT dbo.fnFormatDate(GetDate(), ‘MMMM DDDD DD, YYYY HH:NN:SS AMPM’,…

Read More

PHP Facebook WebCal Parse

Posted on March 18, 2015

I have seen various ways to parse webcal (ical, ics) files in PHP but they tend to get a little more complicated than they need to in some cases or simply do not work. <?phpPHP $icalURL = '<facebook URL>'; echo '<p>iCal URL:<br/>' . $icalURL . '</p>'; $ical = file_get_contents($icalURL); $sED_Start…

Read More

Show Duplicate Records

Posted on February 28, 2013October 26, 2015

These two queries run under different schools of thought and purpose but will help in finding duplicate records. First, if you only want to see the records that are duplicates and the amount of times they appear in the table you could run this code: SELECT memberid ,COUNT(*) AS No_Of_Occurrences…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • Open On Screen Keyboard (OSK)
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes