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

  • Get CPU Information

    You can use the dmesg utility to display the contents of the system message buffer when FreeBSD comes up. For accuracy I recommend querying /var/run/dmesg.boot file. Usually a snapshot of...
  • Using Top [ $top ]

    What is Top? Top provides a live display of information on the CPU processes. Top gets updated periodically as it provides an output CPU level percentage, Memory size, Swap Info,...
  • LAMP STACK

    What is a LAMP Stack? “LAMP stack is a popular open source web platform commonly used to run dynamic web sites and servers. It includes Linux, Apache, MySQL, and PHP/Python/Perl...
  • Identifying malicious mail scripts on FreeBSD

    This article will help you identify an possible spam scripts that may be causing unwanted outbound mail which could cause your servers ip address to be blacklisted.There are many different...