msgbartop
msgbarbottom

18 Jun 09 Change Root Password MySQL

I don’t know how many times I have had to look up this information in the past. In hopes of learning-through-writing I’ve decided to publish these methods of recovering or resetting the MySQL root password.

Set Initial Password

If you’ve just installed MySQL and have never set the root password a password is not yet needed. Until one is defined you should be able to access your database(s) without the password. To set a password for the first time you can use:

mysqladmin -u root password NEWPASSWORD

Update Root Password
If you want to update or change the existing root password you can use:

mysqladmin -u root -p'oldpassword' password newpass

You should note that this will require that you know the current password.

Recover Lost Password

If you have completely lost the MySQL root password and need to reset it you can. This will require short downtime on your database(s). Below are the steps for:

  1. stopping the service.
  2. restarting with bypassed security.
  3. logging into mysql without authentication
  4. inserting a SQL statement, resetting the password.
  5. restarting the database.

Stop the database using one of these commands (Linux vs FreeBSD installations):

/etc/init.d/mysql stop
/usr/local/etc/rc.d/mysql-server stop

Start MySQL in safe mode, bypassing security:

mysqld_safe --skip-grant-tables &

Login to MySQL as the root user. No authentication required:

mysql -u root

Provide the following SQL commands to reset the password. Change “NEWPASSWORD” to your password of choice:

mysql> use mysql;
mysql> update user set password=PASSWORD("NEWPASSWORD") where User='root';
mysql> flush privileges;
mysql> quit

Restart MySQL with new authentication in place:

/etc/init.d/mysql restart

I hope this not only helps me remember these steps but helps others who run into the same problem. I have written about Ubuntu specific instructions for resetting the mysql password. These instructions should be global to any distribution or MySQL installation.

Tags: , , ,

11 Jun 09 MySQL Database Tables Read Only [SOLVED]

After typing out that title I wonder if I’ve been spending too much time on forums, hehe. In any case, I ran into a problem today regarding my database tables being read-only so I thought I’d post this for the good of the internets. I had to dig pretty deep to find a solution to it. Hopefully some additional Google fodder will make life a bit easier for the next guy.

If you’re a regular reader here you know that I had some database problems this morning with this site. I ended up needing to import some databases from backups and manually tweak a few things to restore the lost data. Well it turns out that after a database import or a change of users and permissions your database tables can become read-only. I’m not entirely sure the reasoning behind this, but I found some discussion about it on a MySQL developers mailing list thread.

The solution that I found was to export (read: backup) all of my MySQL databases, and magically things become read-write again. I did this through the phpmyadmin web interface:

  1. Login to /phpmyadmin/ on your site.
  2. Click “Export” in the first column, near the bottom.
  3. Click “Select All” atop your list of databases.
  4. Select any special export options you want (optional)
  5. Click “Save as file” and a compression type. Click Go.

This will export and (optionally) compress your databases into an archive and present it to you as a download through your browser. Tuck it away for safe keeping somewhere and then check your database(s) again. Are they still read-only? If they are you are probably experiencing a different problem than I was, and I’m sorry this didn’t help. If they are now read-write, congratulations!

If anyone can shed any light on the reasoning behind this I’d be very interested to know. Until then, I’ve learned not to question the oddities like this but to simply share the method to the madness. Enjoy.

Tags: , , ,

11 Jun 09 Database Trouble Today

I apologize for the trouble on the site today. I made a minor little mistake with a database and spent the entire day trying to solve it. It appears that everything is working as expected now and I want to thank Stephen Shaw for helping me out, just as I was about to give up. Great work–good eye!

I’m going to make sure I have some healthy backups at this point, and perhaps I’ll find a little time to blog about the whole situation. Mainly what to avoid and what tips I’ve found in the process.

Thank you again for your patience. Let me know if you find anything out of place on the site.

Tags: , ,