FreeBSD MySQL

Reset MySQL Password

Resetting a MySQL Root Password is one of the easiest things to do. However, finding documentation on how to do so can be challenging.

 

We as system administrators, have to reset passwords. Remembering how to do so, is a challenge all in itself. I decided to write a very simple and straight forward article on how to do so. I would assume it could be helpful for future users, as well as myself!

 

This post will show you how to reset the MySQL Root password on FreeBSD. Although similar to Linux, I can assure you this will work on FreeBSD.

 

Step #1 is to start MySQL without grant tables. Keep in mind, if this is a live environment, you will have to restart MySQL. Which means, it will drop any open connections to MySQL during this process for a short period of time.

 

Using your favorite visual text editor. Mine being PICO, do the following when logged into your server.

 

pico /etc/rc.conf

 

Add the following to /etc/rc.conf and then save the file.

 

mysql_args=”–skip-grant-tables –skip-networking”

 

Once completed, you will have to restart MySQL, so it skips password authentication. Next, do the following :

 

/usr/local/etc/rc.d/mysql-server restart

 

Once MySQL Restarts, you should be able to get into MySQL Root without an issue.

Run the following command to gain access to MySQL.

 

mysql -u root -p

 

If it prompts you for a password, just click enter.

 

Once in the mysql command like it should look like this

 

mysql>

 

If so, you were able to skip the Grant Tables, now its time to reset the password.

To reset the password do the following :

 

UPDATE mysql.user SET Password=PASSWORD(‘your new password here’) WHERE USER=’root';

 

The command should execute without a problem, make sure you write down the password! Otherwise, you will have to reset the password once more.

 

The last step, is to go back in /etc/rc.conf/ and remove the following line.

 

Again, you have to open the file by doing the following :

pico /etc/rc.conf

 

Then Remove, the line you inserted in the beginning of this tutorial. If you don’t, MySQL will be wide open to the world!

 

[code]mysql_args=”–skip-grant-tables –skip-networking”[/code]

 

Once again restart MySQL with the following command, and make sure you can get back into MySQL with the password you set!

 

/usr/local/etc/rc.d/mysql-server restart

 

Congratulations, you have now reset your MySQL Root Password on FreeBSD!

 

 

 

 

Related Articles

  • How to Display MySQL Storage Engines

    How to Display MySQL Storage Engines From the MySQL command line, issue the following command: SHOW ENGINES; You should receive a result similar to:   Typically the default storage engine...
  • SSH: Whitelist IPs for Your Server

    If you wish to whitelist certain IP’s for your server for any reason, you can easily go into your Webair Ezpanel for this. When whitelisting an IP, please provide the specific...
  • Extract Tar Files to a Different Directory

    Syntax Typical Unix tar syntax: tar -xf file.name.tar -C /path/to/directory GNU/tar syntax: tar xf file.tar -C /path/to/directory tar xf file.tar --directory /path/to/directory Example: Extract files to another directory In this...
  • Media tools installation Error/Fix

    While installing media tools like Neroacc, we might come across the following errors   ERROR: ====== /usr/ports/audio/linux-neroaaccodec]# make install clean ===>  Staging for linux-neroaaccodec-1.5.1 ===>   linux-neroaaccodec-1.5.1 depends on file: /compat/linux/etc/redhat-release...