Sunday, September 20, 2009

Experiments with My SQL....

Of late I am working with My SQL server, so wanted to share my hands-on experience with blogger world.

Topics covered:
1) How to check My SQL server is up or not and how to start the server.
2) Various command to login to the My SQL server.
3) How to change/reset/recover the root/user passwords.
4) How to take the dump of a My SQL database to a file and how to import it from a file.
5) Executing queries from shell.

Start and Stop….
1) You can check whether My SQL server is up or not by simple unix command given below.
$ ps –ef|grep mysql
The command will show the mysql process running or not.

If the My SQL server is not running, it is very simple to start, execute the following commands in shell prompt.
a) $cd /etc/init.d
b) $./mysql start

The above commands make the My SQL server up.

To stop the My SQL server use
$etc/init.d/mysql stop

Logging in….
2) We can login to the server by any of the below given commands.
a) Without database argument:
 $mysql –u root –p
In the above command –u signifies the option USER (in the command it is “root”) and –p signifies the option “database to be selected” (in the command we have not passed any argument). We will receive the prompt “Enter password:” give the corresponding password. Once we logged into the server it prompts “
mysql>”, which is default, we can set the prompt to our desired one by the below command
mysql> prompt demo$
Prompt will be changed as shown below.
demo$
NOTE: In this article I have used default prompt for easier understandability.

We can see what are the databases existing in the server by following query.
mysql> show databases;

+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test1 |
+--------------------+
3 rows in set (0.00 sec)
Now we can select any database by the following query.
mysql> use [databse_name];
Example:
mysql> use test1;

b) With database argument:
$mysql –u r oot –p test1
We will receive the prompt “Enter password:” give the corresponding password. Here in this command database to be selected is given at command prompt only.

c) Now we see the single line login to My SQL server:
$mysql --user=[user] --password=[password[ [databse]
Example:
$mysql --user=root --password=abc123 test1
Note: “double hyphens” (--) are required in mentioning the arguments, no spaces are allowed before and after “equal to” (=) symbol and the value passed after the password (abc123 in this example) is taken as database to selected, which is optional.

Passwords….
3) If we have not set the root password for My SQL, the server does not require a password at all to login. To set the password for the first time use the following command in shell prompt.
$mysqladmin –u root password NEWPASSWORD

If we want to change the password, use the command given below
$mysqladmin –u root –p ‘oldpassword’ password NEWPASSWORD

  The same command can be used for changing the password for any user by mentioning the user id instead of “root”. For example to change the password for user “USER1” the command is as followed.
$mysqladmin –u USER1 –p ‘oldpassword’ password NEWPASSWORD

Or we can reset the password of any user using My SQL command prompt as shown below.
a) Login to the My SQL server
$mysql – u root –p
b) Select the databse
mysql> use mysql;
c) Change the password for user USER1
mysql> update user set password=PASSWORD(“NEWPASSWORD” )where user=’USER1’;
d) Reload the priviliges
mysql> flush priviliges;
mysql> exit

Even if we forgot the root password to login to My SQL database, we can login to database without the password, in the following way.

a) Stop the My SQL server process in shell
$/etc.init.d/mysql stop
b) Start the MySQL (mysqld) server/daemon process with the --skip-grant-tables option so that it will not prompt for password
$mysqld_safe –skip-grant-tables &
c) Connect to mysql server as the root user
mysql –u root
d) Setup new root password
mysql> use mysql;
mysql> > update user set password=PASSWORD(“NEWPASSWORD” )where user=’root’;
mysql> flush priviliges;
mysql> exit
e) Exit and restart MySQL server
$/etc.init.d/mysql stop
$/etc.init.d/mysql start
  And now we can login to database with the new password we just set.

Taking the database Backup….
4) There is one simplest way to take the back up of a database by the below given command
$mysqldump –u [user] –p [databse] > backupfile.sql
Example:
$mysqldump -u root -p test1 > Mysql_backupfile.sql
By the above command we take the back up of “test1” database to a file “Mysql_backupfile.sql”.

To restore the database from a file is quite easier. Use the command below
$mysql –u [user] -p [database_to_be_restored] < Mysql_backupfile.sql
Example:
$mysql -u root -p test1 < 
Mysql_backupfile.sql

Executing queries from shell….
5) We can execute the insert/update queries from command prompt by using the following command.
$mysql [databse_name] < [filename] -u [user] -p
Example:
$mysql test1 <  file1 -u root -p
Here in the file “file1” we can write our desired insert/update queries. (Each query terminated by a semicolon (;) and the next query in a new line). Execution of the command, prompts for the “root” user password, enter the corresponding password, the data in the “test1” database will be altered or inserted according to the queries given.

You can refer
this link or contact me for any assistance in My SQL.

Tuesday, September 8, 2009

Do not revert/return 'back’

We very often hear people using the word ‘back’ with both ‘revert’ and ‘return’. ‘We will be returning back to Hyderabad on the 20th.’ ‘The software company has asked us to revert back to the older version.’ In both these sentences, the word ‘back’ is unnecessary. When you revert to something, you are ‘returning’ or ‘going back’ to it. There is no need to use the word ‘back’ with ‘revert’.

*The new schedule is creating too many problems. Should we revert to the old one?

In legal contexts, the word ‘revert’ can be used to mean ‘to become the property of a person again.’

*If I lose the case, the property will revert to my brother.

SOURCE: THE HINDU

Wednesday, August 19, 2009

Google Street View

Of late two of my friends have been to US. One has been to Philadelphia \fi-lÉ™-ˈdel-fyÉ™, -fÄ“-É™\ (derived from Greek philein, to love, plus Greek adelphos, brother, i.e., the city of “Brotherly Love”). And the other one has been to Phoenix \fÄ“'nÄ­ks\ (A mythological bird, said to be the only one of its kind, which lives for 500 years and then dies by burning to ashes on a pyre of its own making, ignited by the sun. It then arises anew from the ashes).
Being inquisitive, I checked, how their respective flats/apartments looks like, in Google street view (GSV). GSV gives the omniscient feeling of any place in US, UK, NZ etc; especially if you are anticipated to visit the place. Though Google has launched this feature long time ago, this article is intended to let you know how to use GSV (if you are not familiar beforehand) and to show my friends’ apartments in U.S. :)

How to Use:

Step 1: Login to your Google account and click on "Maps" tab. If you don’t have Google account, you can use GSV from here. Give your desired address in the textbox displayed. Then it gives the destined location with a balloon mark (approximate location) as shown in the below screen shot.


Step 2: Double clicking on the navigation lines (white/green/yellow in color) leads you to the street view of that particular location as shown below screen shot.


Step 3: Drag and drop the stickman in the bird eye view map given at the extreme right hand corner, to navigate directly.GSV allows you to have 360° horizontal and 290° vertical panoramic views from a row of positions along the street, and 2X to 4X zoom of the ambience depending on the availability.

There are many buttons and tabs, privileged to be reconnoitered by you. Enjoy the panorama of the streets.

NOTE: Street View is not available in INDIA and many other countries till date.

Monday, August 10, 2009

Courage: The joy of living dangerously

Prologue:
Frank Lucas a drug lord from America, Frank Abagnale Jr an American security consultant and former check forger, and Osho a spiritual guru, are the people whose way if thinking was utterly out of the box.
Usually I don’t follow the spiritual lectures and practices, but on 10th July, I saw this book, titled "Courage" written by Osho, in our office library. I thought of giving it a try and see what’s in it. 
After couple of days, a friend of mine showed me a vedio of Osho’s addressing to his disciples. It was first time that I heard a speech about a particular English word by a spiritual guru, which left me stupefied.

About the book:
“Life is uncertain and insecure” this is what I heard from many people, but Osho addresses it in the other way. He says “Don’t call it uncertainty - call it WONDER”, “Don’t call it insecurity – call it FREEDOM”. He elucidates about courage and how to live life courageously/dangerously. He discusses about the importance of love, meditation, morals, ethics, dos and don’ts of human life. He addresses about the life before one’s birth, and the views of different communities/religions on how life will be after one’s death, with dainty examples. He also tells us (as in most of the other self-help books) to always get ready to accept the change when it knocks on your door, even if it leads you from bad to worse, you should be ready to accept and embrace the change (read book to know why).
I liked the following example regarding how we need to embrace the change. “When a human being is in mother’s womb, he/she gets everything from mother - food, breath and warmth. It is the best place in the world that a human being can ever live with out toiling much. But we can’t stay there for our lifetime, we have to accept the change and come out of the womb to face this world, where he/she has to strive for their endurance”.
There are few titillating stories like how George Bernard Shaw sold his books, how danger it is to ask time to a Punjabi at 12’o clock.

Few Lines from the book:
A boy was constantly scratching his head. His father looked at him one day and said, “Son why are you always scratching your head?”
“Well,” the boy responded. “I guess because I am the only one who knows it itches.”
The above four lines are enough to depict Osho’s wit and 
astuteness.

Epilogue:
On the whole I enjoyed the book.

Saturday, August 1, 2009

Hand-me-up and hand-me-down

Does the expression ‘hand-me-up’ exist?

Believe it or not, it does. People who have older brothers or sisters will certainly know what ‘hand-me-downs’ are. They are usually clothes which the older child has outgrown, and which the parents give to the next in line. If the clothes are still in good condition, they get handed down to the unfortunate third child. Sometimes, a child grows up wearing hand-me-downs! A ‘hand-me-up’ is the opposite of ‘hand-me-down’. In this case, it is the younger generation which passes things on to the older generation: parents, grandparents, etc. Young people today are very fond of gadgets: computers, IPods, and cell phones are some of the things they must have. They cannot survive without them. Once a particular model becomes outdated, some people immediately go to the market and buy the latest version. What do the youngsters do with the old gadget? Many choose to hand it over to their less tech savvy parents or grandparents. This handing over of used gadgets to the older generation is called ‘hand-me-up’.
*I got this laptop from my daughter. It’s a hand-me-up.

SOURCE: THE HINDU