Friday, November 30, 2007

Removing duplicate entries from a MYSQL table

This is a very easy problem to solve, but when you run into it you just get all be-fuddled and stuff.
Lets say you have a table userinfo which looks like:
userid int
email varchar(50)
first_name varchar(50)
last_name varchar(50)
address varchar(500)
city varchar(50)
state varchar(2)
zip varchar(10)

The best design is to index on userid. If its a web application, then after the initial registration send over a cookie. Upon login, if you can't find a cookie, only then will you need to select on email, which would be their username as well.

OK, so that was a slight digression. But if you didn't index on userid, then your code may have created multiple userid entries, like so:
userid username
100 sandeep
101 loki
102 mari
103 sandeep
104 raja
105 sandeep

So how do you get rid of these multiple entries?
1. Create another table with the unique entries from this table. You're "grouping by" the duplicate entries.
mysql> CREATE TABLE nuserinfo SELECT * FROM userinfo GROUP BY username;

2. Delete the old table:
mysql> DROP TABLE userinfo;

3. Rename the new table:
mysql> RENAME TABLE nuserinfo TO userinfo;

Labels:

How do I change my desktop configuration?

Generally the X server configures itself during installation. Sometimes though you can run into problems. Say you replaced your video card, or changed monitors. You can get funky fonts or a blurry screen which may make you think you hit yourself on your head.

You'll need to reconfigure X:
Applications -> System Settings -> Display

or to run "system-config-display" from the command-line.

This is a RedHat/Centos command.

How do I get xterm to startup and be saved across logins in gnome

One way of course is to log out and say "Save current setup". Where's the fun in that?

Here is another way:

1. Click on Applications -> Preferences -> More Preferences
2. Select "Sessions", which is at the bottom of the menu.
3. Choose the "Startup Programs" tab, click the Add button.
4. Make the order to be 65 (this is assuming your programs in your current session end with order 60)
5. Enter "xterm" in the text window that says "Startup Command".

How do I make sure my email button in gnome launches a new version of ?

1. Right-click the application-launcher for email, which is configured to Thunderbird. This is the mail button on the bottom (could be top) panel.
2. Choose properties
3. In the field that says "Command", change from:
/usr/freeware2/thunderbird/1.5.0/Linux/thunderbird
to
/usr/freeware2/thunderbird/2.0.0.6/Linux/thunderbird

Installing ssh on Solaris

For older systems:

Here are the links I followed for future reference:
http://www.sunfreeware.com/openssh8.html

The script ensures that there is no need to reboot the system:
http://www.tech-recipes.com/solaris_tips1158.html

Thursday, November 29, 2007

MySQL tuning