Wednesday, December 9, 2009

How (& Why) To Install i686 Kernel In Fedora Core 6 in 7 Steps

Anaconda has a well documented defect where it installs i586 based kernel in i686 machines. It causes problems with several drivers including nvidia drivers. Also you will gain performance improvement by moving to i686 kernel. Let's upgrade the kernel in just 7 steps.

First you must verify that you do have a i686 cpu and you have i586 kernel.

Note: All the following commands must be run as root.

1. Run the following from terminal to know your cpu architecture:
arch

2. Now run the following to find out the kernel installed:
yum list kernel

You may get something like this at the end:
kernel.i586 2.6.18-1.2798.fc6 installed
Note the i586. It shows that you have the wrong kernel installed. Let's go to the next step.
Note: If it shows i686 then you needn't proceed further.

3. First save a copy of your grub.conf. You may need it.
cd
cp /boot/grub/ .

4. Next remove the existing kernels.
yum remove kernel
Confirm the removal.
This will remove the kernel and all iuts dependencies. Note the dependencies.You will have to install them later.

You may get a grub error message like:
grubby fatal error: unable to find a suitable template
grubby: doing this would leave no kernel entries. Not writing out new config.

Ignore it.

5. Now install the i686 kernel:
yum install kernel.i686
This will force installation of i686 kernel. Confirm the installation when asked.

You may get grub error like this:
grubby fatal error: unable to find a suitable template

This one is dangerous. If you get it then first fine the exact version of kernel installed as follows:
yum list kernel
You will get a version string like: 2.6.20-1.2933.fc6
Write it down.
Then open grub.conf in any text editor like gedit. I did:
gedit /boot/grub/grub.conf &
Note the line starting with kernel /vmlinuz. Change the version string of vmlinuz to the string you copied before. Double check to ensure there are no typos. Then repeat the process for the line starting with initrd /initrd. Save the file and exit.

6. Now install the dependencies you removed earlier. I did the following:
yum install compiz gnome-volume-manager systemtap gnome-session pcmciautils

7. Reboot and you are done:
reboot

Note: You may get an error while rebooting if you previously ignored the "unable to find suitable template" error or incorrectly modified grub.conf. You will get a second chance to modify it now to make it boot. However if you do have to modify then ensure that you make the same changes in grub.conf so you don't have to type it again and again while rebooting.

Monitoring MySQL Queries Using Bash Script

Monitoring MySQL queries is a favorite pastime of MySQL administrators especially for performance reasons. Here is a simple bash script to monitor long running MySQL queries in realtime using the ubiquitous 'show processlist'. The best part about this script is that you can use it to log your queries over time for later evaluation.


#!/bin/bash
while [ 1 ]
do
mysql -N -u root -ppassword -e 'show processlist' |grep -v 'show processlist'
sleep 2
done



Note: Replace password with your actual password.
Note: -N removes column headers.

This script excludes the show processlist thread itself. You may also exclude the Sleeping threads with the following modification:
mysql -N -u root -ppassword -e 'show processlist' |egrep -v 'Sleep|show processlist'

Note: This is not the only or best solution in market. There is mtop script with more functionality but written in perl. I am alergic to perl and also couldn't get it working in my only attempt. So here is a simple solution in bash. Personally I don't like hacking perl scripts.

Note: You can use slow query log too but in my experience a running top like display is better at finding bottlenecks. Slow query log doesn't indicate why a query took long time. It could be because it was waiting on another query to complete.





How to Change MySQL Password for Other Users

Do you get this error message when you try to change the root password?

mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: YES)'

Or may be you need to change the MySQL password for other users. So what do you do then?

To change a normal user password you need to type:
$ mysqladmin -u user-name -p oldpassword newpass

How to Update or Change Password for a Single User in MySQL and Reload Privileges

MySQL stores usernames and passwords in the user table inside the MySQL database. You can directly update a password using the following method to update or change passwords:

1) Login to the MySQL server, type the following command at the shell prompt:

$ mysql -u root -p

2) Use the mysql database (type commands at the mysql> prompt):

mysql> use mysql;

3) Change password for a user:

mysql> update user set password=PASSWORD("newpass") where User='YOUR-USER-NAME';

4) Reload privileges:

mysql> flush privileges;
mysql> quit


*the above script works only with PHP or pearl scripting*

4 How To Change MySQL Password

Let's look at all the ways to change MySQL password, for root and other users:

In MySQL the default password is empty. This is inherently unsafe and should be immediately changed. Here is how you can change MySQL default root password:

mysqladmin -u root password NEWPASSWORD

Here is how you can change OLDPASSWORD to NEWPASSWORD

mysqladmin -u LOGIN -p OLDPASSWORD NEWPASSWORD

Replace LOGIN with your login name, OLDPASSWORD with your current password and NEWPASSWORD with the new password.


enjoy!

How to Set Up Root Password for Your MySQL Server

If you have never set a root password for MySQL, the server does not require a password at all for connecting as root. To set up a root password for the first time, use the mysqladmin command at the shell prompt as follows:

$ mysqladmin -u root password newpass

If you want to change (or update) a root password, then you need to use the following command:

$ mysqladmin -u root -p oldpassword newpass

I hope this will work for you perfectly.

How to Recover MySQL Root Password

Do you want to recover the MySQL root password. its by no means, easy. But its quite simple if you follow the procedure. You will have to follow this step-by-step processes

Step 1: Stop the MySQL server process.

Step 2: Start the MySQL (mysqld) server/daemon process with the –skip-grant-tables option so that it will not prompt for a password.

Step 3: Connect to the MySQL server as the root user

Step 4: Set a new root password

Step 5: Exit and restart the MySQL server.


Here are the commands you need to type for each step (log in as the root user):


Step 1 : Stop the MySQL service:

# /etc/init.d/mysql stop


Output:

Stopping MySQL database server: mysqld.


Step 2: Start the MySQL server w/o password:

# mysqld_safe --skip-grant-tables &

Output:

[1] 5988
Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe[6025]: started


Step 3: Connect to the MySQL server using the MySQL client:

# mysql -u root

Output:

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.1.15-Debian_1-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>


Step 4: Set a new MySQL root user password:

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


Step 5: Stop the MySQL server:

# /etc/init.d/mysql stop

Output:

Stopping MySQL database server: mysqld
STOPPING server from pid file /var/run/mysqld/mysqld.pid
mysqld_safe[6186]: ended

[1]+ Done mysqld_safe –skip-grant-tables


Now Start the MySQL server and test it:

# /etc/init.d/mysql start
# mysql -u root -p


phew done now enjoy programming