Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Thursday, June 25, 2009

MySql Root Password Recovery

A few of my Linux machines only get accessed remotely from a shell or web interface. Since they are usually very reliable and don't give me any problems I have a tendency to forget about them and all the different passwords that I use on them.

Now being a somewhat security conscious person I use unique and complex passwords for every account and machine that I have control over. I also do not have the best memory in the world so I have used a few of the password manager utilities. I am currently using KeePass and experimenting with LastPass to manage some of my passwords.

But as life would have it I must not have entered or forgotten to update the password for one of my MySql instances and here is how I solved the problem.

This method will take down the MySql daemon for a short time so I first made sure that no important services would be interrupted. Then I stopped the server.


[root@localhost /]# /etc/rc.d/init.d/mysqld stop
Shutting down MySQL: ... [ OK ]


Then start the server skipping the grant table.


[root@localhost /]# mysqld_safe --skip-grant-tables


If the server does not start you probably have other issues but assume that the server started up correctly. Now you need to reset the password. Login to the MySql server.


[root@localhost /]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 33
Server version: 5.1.34 - MySQL Standard Edition (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> update user set Password=PASSWORD('new-password') where user='root';

mysql> flush privileges;

mysql> exit


Now the password has been reset so you need to kill the mysqld process and start the server normally. To kill the server I just grepped for the process number.


[root@localhost /]# ps aux | grep mysql
mysql 8856 ....deletia...
[root@localhost /]# kill -9 8856
[root@localhost /]# /etc/rc.d/init.d/mysqld start
Starting MySQL: ... [ OK ]


Now you should be up and running with a new password and DO NOT forget to update the password manager with the new password.

Thursday, April 30, 2009

SD Card Partitioning

A week or so ago my wife mentioned that she was having a problem with her digital camera. Given the importance of the requester I stopped what I was doing and listened to her describe the problem.

It seemed that the camera was having problems writing to the SD Card and after turning the camera off and on it wanted to reformat the card. This is not a new camera or card so this is something that should not be happening at this point.

I popped the card into my pc and Windows showed that it as a One Gig partition. This was strange because it is a Two Gig card. Opening up Disk Manager showed that indeed there was a One Gig partition and the rest was unused space. I attempted to resize the partition and even create a second partition in that unused space but Disk Manager wasn't going to let me do it.

So I tried inserting the card into my Linux laptop to see what I could do. Mandriva detected the card and auto mounted it as "NEW VOLUME". That was a good sign so dropped to the shell and issued a "fdisk -l" to see what was there but only the hard drive ( sda ) showed up. Then I poked around in /dev/ to see what I can find and didn't notice anything. I issued a "ls" on /mnt and there was nothing there.

After a moment of inspiration I checked /media and there was NEW VOLUME and then after a bit of googling I issued a"cat /etc/mtab" and was rewarded with:

/dev/mmcblk0p1 /media/NEW\040VOLUME vfat rw,nosuid,nodev,uhelper=hal,uid=501,utf-8

Now I was able to unmount using "unmount /dev/mmcblk01p1"

Then I used "fdisk /dev/mmcblk01p1" and selected "d" to delete the partition

Then "w" to write the table to the card.

Then I selected "n" for new partition.

Then "p" for primary.

Then "1" to make it the first partition.

Then "enter" to accept the default first cylinder.

Then "enter" again to accept the default last cylinder.

Then "w" to write the table.

Now the card is partitioned into one partition again and after formatting and putting it back in the camera and taking a few pictures my wife is happily taking pictures again.