How to Reset the Root Password of MySql in Linux

I am posting this for my future reference. Also it my help passers by.

If you are using CentOS 6 (maybe others too). To reset the root password use the following steps:-

  1. sudo service mysqld stop
  2. sudo service mysqld startsos
  3. mysql -u root
  4. Now you will be at mysql prompt. Here type:-
    1. UPDATE mysql.user SET Password=PASSWORD(‘NewPassHere’) WHERE User=’root’;
    2. FLUSH PRIVILEGES;
    3. quit;
  5. sudo service mysqld restart

Your pen drive bigger than 4GB?

Do you know that pen drives are formatted in FAT32? Do you know that maximum file size supported by FAT32 is 4GB? Did you ever try to copy files bigger than 4GB in your pen drive, only to be confronted by some error?

Today we have pen drives of 8GB, 32GB and more capacity ones are coming. It is natural that we try to copy files which are bigger than 4GB into them. Unfortunately FAT32 does not support single files bigger than 4GB. You need to format your pen drive in NTFS for that.

In Windows (XP) when you try to format the pen drive you are provided with FAT32 as the only option. This is probably because of portable nature of pen drives. In NTFS you can set permissions and encrypt files too. These files then may not open on other computers. Furthermore, NTFS needs more writing than FAT32. This is maybe because of the small cluster size of NTFS.

To be able to format pen drives in NTFS you will need to enable “Optimize for Performance” mode. Ples follow through the steps of this excellent article – http://blog.eches.net/tips/how-to-format-usb-drive-with-ntfs/. Ubuntu users should know that this OS already runs in optimized for performance mode.

Using Airtel Edge/GPRS Micromax MMX 610U USB device to surf the internet from Linux

This has been a major headache for me to reboot to Windows just to surf my net, and to update my Linux machine I had to forward the internet connection from a Windows computer to my Linux machine. None-the-less I eventually managed to make it work to day. 🙂

Note that I managed to make it work, and I provide no guarantee that it will work on your computer, but I will share my computer’s configuration so that it may help you.

So, first my computer’s configuration. I have Kubuntu Hardy Heron installed (8.04). My current kernel is 2.6.24-19-generic (installed from the official Ubuntu server). Mine is a 32-bit system. The USB modem I have is Micromax MMX 610U.

Now the steps to setup your USB modem:-

  1. Plug-in your USB modem. A green light will start blinking. If the light is blue then you have PIN set and I have no idea how to enter PIN code from Linux. In that case, reboot to Windows and from the provided Airtel’s software enter the PIN code and reboot to Linux or disable the PIN altogether.
  2. Now run the command lsusb in the console the output will be like as below.Bus 005 Device 003: ID 0d49:7410 Maxtor
    Bus 005 Device 001: ID 0000:0000
    Bus 004 Device 001: ID 0000:0000
    Bus 003 Device 002: ID 046d:c016 Logitech, Inc. M-UV69a Optical Wheel Mouse
    Bus 003 Device 001: ID 0000:0000
    Bus 002 Device 001: ID 0000:0000
    Bus 001 Device 004: ID 12d1:1001 Huawei Technologies Co., Ltd. E620 USB Modem
    Bus 001 Device 001: ID 0000:0000

    An Important Note:-
    As I have found out that hot plugging of this USB modem doesn’t work. The modem will be detected by the kernel but for some reason wvdial won’t be able to locate the modem, hence, when you insert the modem into your USB drive then reboot your computer (or plug it in before turning on your computer).

    Note the bolded text above. That’s your modem.

  3. Now run sudo wvdialconf. This will create the file /etc/wvdial.conf with some of the necessary values.
  4. Now whatever values the file /etc/wvdial.conf keep that as such except for the ones shown below. If any settings shown below already existed then replace that with the ones below, if they didn’t exist then just add them to the file, but they must appear below the line [Dialer Defaults]. Note that will need to open the file /etc/wvdial.conf as a root. Try using sudo nano /etc/wvdial.conf.Init1 = AT+CGDCONT=1,”IP”,”airtelgprs.com”,””,0,0
    Baud = 460800
    stupid mode = 1
    Phone = *99#
    Password = a
    ;No need to change this to anything else. This is immaterial, and note that no semicolon before Password =.
    Username = a ;No need to change this to anything else. This is immaterial, and note that no semicolon before Username =.
  5. Now create a file connAir in your home directory. Copy and paste the following code into it and give it execute permission.
    [code lang=”bash”]#!/bin/bash
    # BY AppleGrew @ http://blog.applegrew.com (All rigths
    # reserved)

    pid=`pgrep wvdial`
    if [ -z $pid ]
    then

    sudo route del default
    echo "CONNECTING TO Airtel…"
    wvdial &

    sleep 10s

    IP=`ifconfig ppp0|grep -o  ‘inet addr:\([.0-9]*\)’`
    IP=`echo $IP|sed  ‘s/inet addr:\([.0-9]*\)/\1/g’`
    echo "YOUR CURRENT IP IS ‘$IP’".
    if [ -z $IP ]
    then
    echo "CONNECTION TO Airtel TIMED-OUT…….. : ("
    else
    echo "CONNECTED TO Airtel. : )"
    fi
    sudo route add default gw $IP

    else
    echo "A CONNECTION IS ALREADY IN PROGRESS."
    fi[/code]

  6. Now create another file disconnAir in your home directory. Copy and paste the following code into it and give it execute permission.
    [code lang=”bash”]#!/bin/bash
    # BY AppleGrew @ http://blog.applegrew.com (All rigths
    # reserved)

    pid=`pgrep wvdial`
    if [ -z $pid ]
    then
    echo "NO CONNECTION IN PROGRESS."
    else
    echo "DISCONECTTING FROM Airtel…"
    kill -INT $pid

    sleep 6s
    pid=`pgrep wvdial`
    if [ -z $pid ]
    then
    echo "DISCONNECTED."
    else
    echo "DISCONNECTION MAY HAVE FAILED."
    fi
    fi[/code]

Connecting to Airtel:-

  1. Open console and type ./connAir.

Disconnecting from Airtel:-

  1. Open console and type ./disconnAir.

Hope this helps.

Grep: The single most useful command of Linux.

I love Linux. Why? Because it has so many cool cool cool … commands like grep, sed, find, etc. Of all the commands, I use grep the most. If grep is taken out of Linux then I will be severely crippled. Almost everyday I need to use it.

I will give you a recent case where I fixed a bug in LinuxDCpp in just 15 mins even when I had never looked into its code before and I had absolutely no experience building GUI applications in C++ or using GTK libraries.

I am using LinuxDCpp 1.0.1 which has a problem of not beeping when private messages are received even when I have configured it to do so. Because of this I had to repeatedly open the window of LinuxDCpp to check for new private messages. Then, one fine day I decided to fix this. The only problem was how and where. To answer my these questions I needed a starting point to start searching from. I had an idea; I realized that the best place to start searching from is the text – “Beep every time a private message is received“, this is the text that is displayed in the Preferences dialog of LinuxDCpp. I then un-tared the the source code of LinuxDCpp and opened the console in that directory, then I ran the command

$ grep -Rl "Beep every time a private message is received" .

Which yielded the result

./glade/settingsdialog.glade

I then opened that file and located the message. The code there read as following.

<child>
<widget class="GtkCheckButton" id="soundPMReceivedCheckButton">
        <property name="visible">True</property>
        <property name="can_focus">True</property>
        <property name="label" translatable="yes">
             Beep every time a private message is received</property>
        <property name="use_underline">True</property>
        <property name="draw_indicator">True</property>
</widget>
<packing>
        <property name="expand">False</property>
        <property name="fill">False</property>
</packing>
</child>


From my experience of HTML and common sense, I knew that soundPMReceivedCheckButton is the text that need to search for next. Hence I ran the command

$ grep -Rl "soundPMReceivedCheckButton" .

Which yielded the output

./linux/settingsdialog.cc
./glade/settingsdialog.glade

The second line was expected, but the first line contained the destination I must head to next. The code in that file read

// Sounds
sm->set(SettingsManager::PRIVATE_MESSAGE_BEEP, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(getWidget(
  "soundPMReceivedCheckButton"))));
sm->set(SettingsManager::PRIVATE_MESSAGE_BEEP_OPEN, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
  getWidget("soundPMWindowCheckButton"))));

From here on knowledge of C++ was required, but still grep was helpful. The lines spoke to me that there is a an object ‘sm’ which has a method ‘set’ which allows to set the properties of the program. PRIVATE_MESSAGE_BEEP is a constant which means that LinuxDCpp must beep on receiving the private message. From common sense, I concluded that the part of the program which actually generated the beep too must check for whether the property is SettingsManager::PRIVATE_MESSAGE_BEEP or not; in other words, that part of the program too must have the text PRIVATE_MESSAGE_BEEP. Hence my next command

$ grep -Rl "PRIVATE_MESSAGE_BEEP" .

I got the following outputs.

./client/SettingsManager.cpp
./client/SettingsManager.h
./linux/settingsdialog.cc
./linux/privatemessage.cc

As we already have seen the definition SettingsManager::PRIVATE_MESSAGE_BEEP, which clearly meant that PRIVATE_MESSAGE_BEEP must have been defined in the file SettingsManager.h. The only interesting result among them is privatemessage.cc. There I at last found what I was looking for. The code read

if (BOOLSETTING(PRIVATE_MESSAGE_BEEP_OPEN))
  gdk_beep();

In that very file the searched for gdk_beep() which took me to the code

if ((state & GDK_WINDOW_STATE_ICONIFIED) || mw->currentPage_gui() != getContainer())
  gdk_beep();

This is the code which was actually triggered on receiving private message and the code above that is activated when the private message window is opened.

The clear culprit was gdk_beep(). From Goggling out I found that it is part of GTK/GDK library and it is supposed to produce a beep from the internal speaker of the computer, but as per the many posts I saw on the various forums, it usually didn’t work. The only solution was to replace that with some other code. The easiest I could think of was using an external command to play a sound file. I opted for aplay which is usually installed on all current Linux computers. Also, I coded it such that user can configure LinuxDCpp to use any other commands by setting LINUX_DCPP_SND environment variable to the command to execute on receiving private message. For that I replaced

if (BOOLSETTING(PRIVATE_MESSAGE_BEEP_OPEN))
  gdk_beep();

with

if (BOOLSETTING(PRIVATE_MESSAGE_BEEP_OPEN))
{
//Added by AppleGrew
const char *sndCmd = getenv("LINUX_DCPP_SND");
if(!sndCmd) {
        string cmd = "aplay \"/usr/local/linuxdcpp/ping.wav\"";
        system(cmd.data());
}else{
        system(sndCmd);
}

I then edited the SConstruct file to automate the copying of the ping.wav file. For that added th following codes.

snd_file = ['ping.wav']
env.Alias('install', env.Install(dir = env['FAKE_ROOT'] + env['PREFIX'] + '/share/linuxdcpp', source = snd_file))

But, there was still a big problem. The SConstruct allowed the user to install it in /usr directory (the default is /usr/local). That meant I somehow needed to find out during runtime the location of the files. LinuxDCpp was already able to locate its pixmap (graphics) files, which are stored in the location – prefix_loc/pixmaps (prefix_loc is either /usr or /usr/local), I just needed to locate that code. It was clear that whatever mechanism LinuxDCpp was using, it will undoubtedly return the location /usr or /usr/local, and hence the code that accessed the pixmap files then would have to create the pixmap location as

string pixmap_location = function_or_method_that_gives_the_prefix_location + "/pixmaps"

Hence I ‘grepped’ for pixmaps.

$ grep -Rl "pixmaps" .

Which yielded

./Changelog.txt
./Readme.txt
./linux/hub.cc
./linux/mainwindow.cc
./SConstruct

And then and there I found what I was seeking.

// Load icons. We need to do this in the code and not in the .glade file,
// otherwise we won't always find the images.
string file, path = WulforManager::get()->getPath() + "/pixmaps/";

WulforManager::get()->getPath() was the method I needed. Now the new code in privatemessage.cc read

if (BOOLSETTING(PRIVATE_MESSAGE_BEEP_OPEN)){
//Added by AppleGrew
const char *sndCmd = getenv("LINUX_DCPP_SND");
if(!sndCmd) {
        string cmd = "aplay \"" + WulforManager::get()->getPath() + "/ping.wav\"";
        system(cmd.data());
}else{
        system(sndCmd);
}[/code]

This was it. Nice and smooth. I still don't know anything about WulforManager or SettingsManager declarations or the GTK libraries, yet I could finish this up fast and smoothly. All thanks to grep!

Find the number of lines of code your project has.

After completing a big and satisfying project you may want to collect various stats about your project. One of them is the total number of lines of code your project has. As with all big projects it will probably have large number of files tucked into various directories and sub-directories and sub-sub-directories,…. you get the idea; this is very tedious to do manually.

In Linux you have a cool trick to do just that! Run the following in the directory with contains your source code.

find . -type f -exec cat ‘{}’ \;|wc -l

If the directory also contains files other than the source code, e.g. .class files along with .java files, then you can ask find to choose files with a particular pattern using the following command

find . -type f -iname “*.java” -exec cat ‘{}’ \;|wc -l

The above command will choose only .java files.