Monday, August 30, 2010

How to Reset the Root Password for MYSQL DB

Windows Systems
On Windows, use the following procedure to reset the password for all MySQL root accounts:
  1. Log on to your system as Administrator.
  2. Stop the MySQL server if it is running. For a server that is running as a Windows service, go to the Services manager: From the Start menu, select Control Panel, then Administrative Tools, then Services. Find the MySQL service in the list and stop it.
    If your server is not running as a service, you may need to use the Task Manager to force it to stop.
  3. Create a text file containing the following statements. Replace the password with the password that you want to use.
    UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
    FLUSH PRIVILEGES;
    Write the UPDATE and FLUSH statements each on a single line. The UPDATE statement resets the password for all root accounts, and the FLUSH statement tells the server to reload the grant tables into memory so that it notices the password change.
  4. Save the file. For this example, the file will be named C:\mysql-init.txt.
  5. Open a console window to get to the command prompt: From the Start menu, select Run, then enter cmd as the command to be run.
  6. Start the MySQL server with the special --init-file option (notice that the backslash in the option value is doubled):
    C:\> C:\mysql\bin\mysqld-nt --init-file=C:\\mysql-init.txt
    If you installed MySQL to a location other than C:\mysql, adjust the command accordingly.
    The server executes the contents of the file named by the --init-file option at startup, changing each root account password.
    You can also add the --console option to the command if you want server output to appear in the console window rather than in a log file.
    If you installed MySQL using the MySQL Installation Wizard, you may need to specify a --defaults-file option:
    C:\> "C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqld-nt.exe"
             --defaults-file="C:\\Program Files\\MySQL\\MySQL Server 5.0\\my.ini"
             --init-file=C:\\mysql-init.txt
    The appropriate --defaults-file setting can be found using the Services Manager: From the Start menu, select Control Panel, then Administrative Tools, then Services. Find the MySQL service in the list, right-click it, and choose the Properties option. The Path to executable field contains the --defaults-file setting.
  7. After the server has started successfully, delete C:\mysql-init.txt.
You should now be able to connect to the MySQL server as root using the new password. Stop the MySQL server, then restart it in normal mode again. If you run the server as a service, start it from the Windows Services window. If you start the server manually, use whatever command you normally use.
Unix Systems
On Unix, use the following procedure to reset the password for all MySQL root accounts. The instructions assume that you will start the server so that it runs using the Unix login account that you normally use for running the server. For example, if you run the server using the mysql login account, you should log in as mysql before using the instructions. Alternatively, you can log in as root, but in this case you must start mysqld with the --user=mysql option. If you start the server as root without using --user=mysql, the server may create root-owned files in the data directory, such as log files, and these may cause permission-related problems for future server startups. If that happens, you will need to either change the ownership of the files to mysql or remove them.
  1. Log on to your system as the Unix user that the mysqld server runs as (for example, mysql).
  2. Locate the .pid file that contains the server's process ID. The exact location and name of this file depend on your distribution, host name, and configuration. Common locations are /var/lib/mysql/, /var/run/mysqld/, and /usr/local/mysql/data/. Generally, the file name has an extension of .pid and begins with either mysqld or your system's host name.
    You can stop the MySQL server by sending a normal kill (not kill -9) to the mysqld process, using the path name of the .pid file in the following command:
    shell> kill `cat /mysql-data-directory/host_name.pid`
    Use backticks (not forward quotation marks) with the cat command. These cause the output of cat to be substituted into the kill command.
  3. Create a text file containing the following statements. Replace the password with the password that you want to use.
    UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
    FLUSH PRIVILEGES;
    Write the UPDATE and FLUSH statements each on a single line. The UPDATE statement resets the password for all root accounts, and the FLUSH statement tells the server to reload the grant tables into memory so that it notices the password change.
  4. Save the file. For this example, the file will be named /home/me/mysql-init. The file contains the password, so it should not be saved where it can be read by other users.
  5. Start the MySQL server with the special --init-file option:
    shell> mysqld_safe --init-file=/home/me/mysql-init &
    The server executes the contents of the file named by the --init-file option at startup, changing each root account password.
  6. After the server has started successfully, delete /home/me/mysql-init.
You should now be able to connect to the MySQL server as root using the new password. Stop the server and restart it normally.
Generic Instructions
The preceding sections provide password-resetting instructions for Windows and Unix systems. Alternatively, on any platform, you can set the new password using the mysql client (but this approach is less secure):
  1. Stop mysqld and restart it with the --skip-grant-tables option. This enables anyone to connect without a password and with all privileges.
  2. Connect to the mysqld server with this command:
    shell> mysql
  3. Issue the following statements in the mysql client. Replace the password with the password that you want to use.
    mysql> UPDATE mysql.user SET Password=PASSWORD('MyNewPass')
        ->                   WHERE User='root';
    mysql> FLUSH PRIVILEGES;
    The FLUSH statement tells the server to reload the grant tables into memory so that it notices the password change.
You should now be able to connect to the MySQL server as root using the new password. Stop the server and restart it normally (without the --skip-grant-tables option).

Wednesday, August 11, 2010

Windows PS and Kill Command Equivalents

tasklist /v  - equivalent to ps aux
taskkill /f /im ncover*  - equivalent to kill -9 ncover*

Wednesday, July 28, 2010

Lock Screen Keyboard Shortcut for OSX

You can either turn the lock icon on the menu bar through KeyChain Access Preferences or press: [Ctrl + Shift + Eject] on the keyboard

Monday, July 26, 2010

How to reset OSX admin account

Some settings changed on my machine which stopped me from being able to log in. The only way I was able to get around this was to do the following:
  1. Reboot
  2. Hold apple + s down after you hear the chime.
  3. When you get text prompt enter in these terminal commands to create a brand new admin account (hitting return after each line):
    • mount -uw /
    • mv /var/db/.AppleSetupDone /var/db/.AppleSetupDone.old
    • shutdown -h now
  4. Start machine again and setup new admin account
  5. Fix the problem (in my case network users had been disabled)
  6. Log out
  7. Log in as your usual user to test all has been fixed
  8. If all good restart the machine and repeat steps 2 - 3 reversing the following
    • mv /var/db/.AppleSetupDone.old /var/db/.AppleSetupDone
  9. Start the machine and log into you usual user/admin account
  10. Delete the newly created admin account from the System preferences -> Accounts

Monday, July 12, 2010

Pesky Unread Mail Count in Mac Mail

I tried everything to get rid of the unread mail count because clearly I didn't have any unread mails.

Well it just happens that there were a couple of emails that were in conflict (who knows with what) and this was causing the unread mail count to display.

To solve this I did the following.

1. Choose "Mailbox -> New Smart Mailbox" from the mail applications menu bar.
2. Set the rule in the New Smart mail box to match only unread emails

3. Click the "OK" Button.

You should now be able to find any unread emails. 

Sunday, June 20, 2010

Batch Resize Images on Snow Leopard using Preview App

  1. Open all images in preview
  2. Select all images in the selection panel
  3. Choose Tools ▸ Adjust Size
  4. Set the width, height and resolution for your batch of images then click OK
  5. Confirm the changes by saving your batch of images: File ▸ Save All (keystrokes Option-Command-S)

Sunday, May 30, 2010

Boot Snow Leopard in 64 bit mode by default

 First check if your mac has 64bit EFI open up a terminal window and type the following:
ioreg -l -p IODeviceTree | grep firmware-abi

Your result should be: "EFI32" or "EFI64"
If it is the latter then your good to go.

You can either hold down the '6' and '4' buttons during boot up every time or you can modify the following file to permanently boot in 64bit mode:
/Library/Preferences/SystemConfiguration/com.apple.Boot.plist 
All you need to do is add the "arch=x86_64" as the value for the "Kernel Flags" key and restart your machine.  I recommend using a terminal window to do this as you will need to do a sudo.
I use "vi" so I will do the following:
sudo vi /Library/Preferences/SystemConfiguration/com.apple.Boot.plist 
[if prompted enter your user password]
 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
 <key>Kernel</key>
 <string>mach_kernel</string>
 <key>Kernel Flags</key>
 <string>arch=x86_64</string>
</dict>
</plist> 
 
Save and close the file.
Reboot your machine and your done. 

Wednesday, May 19, 2010

Creating Mysql User Accounts

shell> mysql -u root [-p]
shell> CREATE USER 'user_name'@'localhost' IDENTIFIED BY 'some_pass';
shell> GRANT ALL PRIVILEGES ON *.* TO 'user_name'@'localhost' WITH GRANT OPTION;
shell> CREATE USER 'user_name'@'%' IDENTIFIED BY 'some_pass';
shell> GRANT ALL PRIVILEGES ON *.* TO 'user_name'@'%' WITH GRANT OPTION;

Monday, May 17, 2010

iPhoto always asks to import photos on startup

Opening iPhoto, you always see an alert similar to the following:
  • "A photo has been found in the iPhoto Library folder that was not imported. Would you like to import it?"
Easy to fix.
  1. Open up finder and navigate to the "iPhoto Library" package
  2. Right click and choose "show package contents"
  3. Locate the "Recovered Photos" or "Import"
  4. Move it to your desktop
  5. Restart iPhoto
  6. Make sure your photos are still in iTunes
  7. Delete the "Recovered Photos" or "Import" that you placed on your desktop
Important: Be careful not to remove any other folders or items from the iPhoto Library folder. Doing so could cause your iPhoto library to become unreadable.

Thursday, May 13, 2010

Setting SSL certificates for svn and svnX and other svn clients

On Mac OSX locate your .subversion directory usually under the user home directory.
cd into it and edit the servers file with your editor of choice.

Add the following line under the [global] section
ssl-client-cert-file = /Users/[your_user_account]/.subversion/auth/[CERT_FILE]

This will cause the subversion server that requires a certificate to ask you for a password the first time. After this you don't need to keep specifying the file location or password.

Recursively remove folders

To remove a set of directories with the same name recursively is quite simple under unix/linux

Finding the directories to delete in this example .svn directories the following command can be used: "find . -type d -name .svn"

This command says "find from within (.) the current directory files of type (d [directories]) with the name .svn. This is done recursively.

Combining this command with an rm -rf will achieve the desired result.

rm -rf `find . -type d -name .svn`

Monday, April 26, 2010

Uninstall ruby gems by version

# Find out the directory where the gem is installed
gem list -d

# run the following command
sudo gem uninstall --install-dir=

# Follow prompts.

Wednesday, April 21, 2010

Uninstall Mysql from Snow Leopard

Depending on your mysql installation directories [mine is /usr/local/mysql]:

1. sudo rm /usr/local/mysql
2. sudo rm -rf /usr/local/mysql*
3. sudo rm -rf /Library/StartupItems/MySQLCOM
4. sudo rm -rf /Library/PreferencePanes/My*
5. (Edit /etc/hostconfig) sudo vi /etc/hostconfig (Remove line MYSQLCOM=-YES)
6. sudo rm -rf /Library/Receipts/mysql*
7. sudo rm -rf /Library/Receipts/MySQL*
8. sudo rm -rf /var/db/receipts/com.mysql.*

SVN ignore files from command line OSX/Unix

You may need need to set an editor of choice before you can do this.

run the "export SVN_EDITOR=vim" on the command line or put the command in your .bash_profile or equivalent system file.

To actually ignore the "ignorable_file" in a directory do the following.

1. cd the_dir_that_contains_the_file_to_be_ignored
2. svn propedit svn:ignore . # opens vim in my case since this is my editor of choice. See above
3. add the filename of the file to be ignored (ignorable_file in this case) in the open svn properties file.
4. save the file and exit.
5. svn propget svn:ignore . # So you can see the properties
6. svn status --no-ignore # You should see an 'I' next to the ignored files
7. svn commit -m "comment goes here"

Tuesday, April 20, 2010

Update iPhone OS to OS 4 Beta For Mac Users

This is actually quite simple.

1. Make sure that the new OS version is compatible with your iPhone/iPod Touch by reading the FAQs and other goodies on the apple dev sites.
2. Download the Beta if you have a developers account.
3. Extract it to a directory of your choice.
4. Open iTunes and plug your phone/ipod touch in to your usb port on your computer.
5. Make sure you back up your iPhone.
6. Hold down the ALT key on your keyboard and click restore in itunes.
7. A dialog pops up. Navigate to the directory where the new image that you wish to install is and select it.
8. Confirm that you want to update and away you go.
9. When update is complete do a restore from your last backup which will copy all your content back to your iPhone.
10. WARNING: The pre-release softwares are only meant for testing and development. So UPDATE AT YOUR OWN RISK.

Wednesday, April 7, 2010

Itunes iPhoto Sync doesn't work

I have been syncing photos from iPhoto onto my 3GS 32GB iPhone and my wifes 16GB iPhones, using iTunes, for a while now. All of a sudden I was getting the following message pop up at the end of the sync and no photos had sync'd

[The iPod "name" cannot be synced. The required file cannot be found]

Short of trying almost everything to fix this I finally came across the solution.

1. Open up finder and navigate to the "iPhoto Library" package
2. Right click and choose "show package contents"
3. Delete the ipod cache folders

It seems that they had become corrupt and this was causing the issue.

Now all syncs fine again.

Update: another issue with photos not syncing is that they are removed by default if you are syncing video/audio etc, that is larger than the capacity of free memory left on the device.

Mac OSX Screen Capture

You never really think about capturing an image of the screen or part of it until you actually have to do it. With Windows it was simple since there is a button in most cases on the keyboard to do this. With Mac OSX it is also easy you just need to know the shortcuts.

All files saved by default to the Desktop as .PNG files otherwise they are stored in the clipboard

Capture the entire desktop
Command-Shift-3

Copy the entire desktop (to the clipboard)
Command-Control-Shift-3

Capture a portion of the desktop
Command-Shift-4
Control-Command-Shift-4 (capture to clipboard)
(Drag the cross-hair cursor that appears around the area you wish to capture)

Capture a specific application window
Command-Shift-4, then Spacebar
Control-Command-Shift-4, then Spacebar (capture to clipboard)

Using the bundled Mac OS X Grab Utility
Applications > Utilities > Grab
(Useful if you need to include a cursor or a menu in your screen shot, or if you want to save your screen shot to TIFF format)

Include a cursor
Go to Grab Preferences and select the cursor icon you wish to have in your screen shot.
Capture Types from Capture Menu (or keyboard shortcut):
  • Selection (Shift-Command-A) [Cursor not included in capture]
  • Window (Shift-Command-W)
  • Screen (Command-Z)
  • Timed Screen (Shift-Command-Z) [An instruction window will appear that allows you to prepare your screen for capture. When ready, press the "Start Timer" button and you will have ten seconds before the screen is captured. This allows you to open menus and sub-menus, if necessary]

Sunday, March 28, 2010

sudo: must be setuid root

I did a silly thing this morning. I "chown"ed my /usr directory on my macbook pro to my username. This broke all commands like sudo, su etc and they became unusable. I couldn't chown it back to root anymore.

After a long hard search for 2 or even more hours I remembered seeing something about disk permissions in the mac osx "disk utility".

A quick "Command-Spacebar" to bring up spotlight search dialog, and then type in disk utility brings up the following window.


Selecting the drive to repair and clicking the "Repair Disk Permissions" Button at the bottom repairs all permissions on the file system.

Now I can "sudo" and "su" again.

Software and Dev Fixes

Hi Peoples.

I have finally had enough of crappy solutions to simple problems and situations. What pushed me over the edge was a permission issue on my mac, yes due to user error on my part. Searching for a solution for over an hour got me nowhere. Then I remembered something .... and fixed it in no time.

I decided to created this blog for the sole reason of keeping track of these issues. It will also be a place for people who develop in Java/Ruby/Objective C etc and also Mac/Windows users. I will place details of my solutions here. I hope it is useful to someone out there.

I will only blog when I come up with a solution to a problem I face. Mainly for me to remember and for others to reference. Granted some problems even though being the same might have different solutions on different platforms and might not be covered here. That is what the comments section is for. So feel free to use it.