Sql On linux

Posted: November 14, 2008 by Narendra Shah in Linux Box
Tags: , ,

Let us see how Linux and OSS liberate us altogether from the invisible chains of the propriety software:

Do you know that if you get a CD of the Oracle software from some friend, you are using pirated software which is not at all good?
Did you know that if you buy a genuine version of Oracle DBMS, it may cost you very well over the cost of your PC?
Did you know that we have a free DBMS software called MySQL which is free and is as powerful as Oracle; and that major companies like Yahoo, AOL, ebay, amazon and GOOGLE use it to provide you services?

Some additional points may be noted:

* In most cases, you will not get oracle for Linux.

* Oracle is available for Linux but it is a real challenge to get a PIRATED version for free for the Linux OS.

* Oracle installation can slow down your Windows like a tortoise.

* I have seen the Oracle installations failing. They either do not start or do not install at the first place! ( Actually I too tried it, but failed! SO I thought why not look into the open source software area?)

So what should the students do? Students do not need a costly software to practice commands. Also, we do not want our PCs to slow down because of Oracle! So what to do? Here is what to do:

As I mentioned, there exists a powerful DBMS software called as MySQL on Linux (and for Windows as well) which can be downloaded and used for free! SO why go with software piracy and decrease the system performance? Get free and use MySQL. Believe me, it is much easier for students to use it!

Here is the way to help you configure MySQL on Your Linux system. Since I use openSUSE 11.0, I will use the openSUSE 11.0 system in this guide.

To make the MySQL DBMS work for you, you need to follow the following steps:

STEP 1:

Install MySQL on your Linux system. It usually comes inbuilt into most of the Linux DVDs (e.g. in openSUSE 11.0 DVD). So if it is not already installed, just open your software package manager and install it. If you have problems doing so, reply back in this post and I (and others) will try to solve your problems.

STEP 2 :

Start MySQL. To do this, you need to use the root account. so go as follows:

(i) –> Start the shell prompt.
(ii) –> Switch to the root user account by passing the su command. It will ask for the root password. Enter the password.
(iii) –> Now, to start the mysql service, you need to enter the following command:

Code: Select all
# service mysql start
You will have to do this everytime you start the system.

If you want the MySQL service to start automatically on each boot, follow the following steps (in openSUSE only):

1. Start yast

2. It will ask for the root password. So enter the root password and continue.

3. After the Yast window comes up, first click on the ‘System’ option on the left pane and then click the “System Services (runlevel)’ option on the right pane. This will open a new window where you can change the settings.

4. In the new window that opened (the system service configuration window), look for the entry ‘mysql’ in the ‘service’ column.

5. Click (not double click) the ‘mysql’ entry and on the bottom, click on the ‘Enable’ button. It takes few seconds. Wait for that time. Now click the ‘Finish’ button in the same window.

Wow! Now, the MySQL service will start automatically everytime you start the system!

After the MySQL service has started, you can close the shell prompt.

STEP 3:

Using the MySQL for the first time needs you to configure it. For that you will have to do the following:

(i) –> open the shell prompt and type the command : mysql
(ii) –> This will bring you the mysql prompt. It should look as below :

mysql>

(iii) –> type the following command at the mysql prompt :

Code: Select all
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'my-password';

NOTE:

The above command will create a user ‘root’ (which can administer the database and sets its password to my-password. If you want some other password, change my-password to a password of your choice.

It should say something like :

Query OK. 0 rows affected (0.01 sec)

Now, your mysql is configured! And it is ready to be used!

STEP 4:

Using MySQL now onwards is very easy. Now everytime you need to use mysql , you will need to pass the following command at the shell prompt:

Code: Select all
$ mysql -h localhost -u root -p

This will ask you the password you had provided while configuring the MySQL for first use (it is the last word in the single quotes in the “GRANT ALL PRIVILEGES … ” command). In this case, it will be my-password.

NOW, it is ready to be used!

Yes, if you see the size of the post, it is long, but if you look at what has to be done, isn’t it easy? I think it is very easy; specially when you save thousands of rupees, the speed of computer and are not using pirated software!

USING MYSQL AFTERWARDS

Now, before you go on trying some commands wildly and thinking why it is not working, I must tell how to make MySQL to work.

In the beginning, there are no databases you could use. So you need to create a database first.

CREATING A DATABASE

To create a Database, pass the following command at the ‘mysql> ‘ prompt:

syntax:

Code: Select all
create database <database name>

the above will create a database with the name given at the place of <database name>.

Example:

Code: Select all
create database mydb1

this will create a database with name ‘mydb1’ on your computer.

SELECTING THE PROPER DATABASE TO WORK WITH

There may be many databases that you will need to create. So you first need to select which database you want to work on. For that you need to pass the following command on the ‘mysql> ‘ prompt:

syntax:

Code: Select all
use <database name>

The above command will make the wanted database (whose name you write in place of <database name> as the database in use and all the queries that you type will work on that database.

example:

Code: Select all
use mydb1

this will make the ‘mydb1’ database as active and all the commands that you pass will be considered for this database.

Now is that not easier than oracle where each time you need to work on a different database, you need to load a different database and restart the SQL prompt?

I think that once you have done the required step, you will not need anything more than a command (and a password) to use the database. Its easy, right?

MySQL is also available for windows. Just remember that you need to download the installer and in the first configuration steps you will be aske the root password. Also, it is easy to be accessed form the start -> all programs -> MySQL menu. All other configurations are done by the first configuration wizard. just remember that you need to read carefully through the wizard and follow all steps attentively. Once done, it is ready to run!


Advantages of MySQL
:

1. Free of cose
2. Does not slow down the PC.
3. Takes no time to start.
4. No need to select a database, and mount it and then start the SQL each time you need to use it.
5. can switch between different databases fast.

So I hope you have understood how to use MySQL. If you still have problems, write back in the thread. And please comment on the guide; whether it was excellent, very good, good, satisfactory, bad or useless.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s