Archive

Posts Tagged ‘Install MySql’

How to : Installing MySQL on Linux and Basics – Tutorial

It’s simple to install MySQL on Linux using the RPM file.

1. Become the superuser if you are working in your account. (Type “su” and the prompt and give the root password).
2. Change to the directory that has the RPM download
.
3. Type the following command at the prompt:

rpm -ivh “mysql_file_name.rpm”

Similarly you can also install the MySQL client and MySQL development RPMs if you’ve downloaded them.
Alternatively, you can install the RPMs through GnoRPM (found under System).
4. Now we’ll set a password for the root user. Issue the following at the prompt.

mysqladmin -u root password mysqldata

where mysqldata is the password for the root. (Change this to anything you like).
5. It is now time to test the programs. Typing the following at the prompt starts the mysql client program.

mysql -u root -p

The system asks for the the password. Type the root password (mysqldata).
If you don’t get the prompt for password, it might be because MySQL Server is not running. To start the server, change to /etc/rc.d/init.d/ directory and issue the command ./mysql start (or mysql start depending on the value of the PATH variable on your system). Now invoke mysql client program.
6. Once MySQL client is running, you should get the mysql> prompt. Type the following at this prompt:

show databases;

7. You should now get a display similar to:

+—————-+
| Database |
+—————-+
| mysql |
| test |
+—————-+
2 rows in set (0.00 sec)

Okay, we’ve successfully installed MySQL on your system. Now let’s look at some MySQL basics.

MySQL database introduction: MySQL beginners tutorial

The MySQL database package consists of the following:

* The MySQL server: This is the heart of MySQL. You can consider it a program that stores and manages your databases.
* MySQL client programs: MySQL comes with many client programs. The one with which we’ll be dealing a lot is called mysql (note: smallcaps). This provides an interface through which you can issue SQL statements and have the results displayed.
* MySQL client Library: This can help you in writing client programs in C. (We won’t be taking about this in our tutorial).

The difference between MySQL and mysql

MySQL is used to refer to the entire MySQL distribution package or the MySQL server, while mysql refers to a client program.
Why have client and server programs?

The server and client programs are different entities. Thus, you can use client programs on your system to access data on a MySQL server running on another computer. (Note: you would need appropriate permissions for this. Consult the system administrator of the remote machine.)
Dividing the package into a server and clients separates the actual data from the interface.

MySQL primer – Creating a database

In this section of the MySQL primer we will learn how to create a database.

The commands for creating a database in Windows and Linux are the same. However, the prelimnary commands in Linux are slightly more complex. Since this tutorial is meant for the complete newbie, I’ll discuss the Windows and Linux systems separately.
We’ll create a database called employees that contains details of employees of our company ABC Pvt Ltd. The details we plan to store would be names, salaries, age, addresses, emails, birth dates, hobbies, phone numbers etc.

Creating MySQL database on Windows system

1. Start the MySQL server by issuing the command mysqld-shareware –standalone at the prompt in c:\mysql\bin. Refer the previous session Installing MySQL on Windows for further details.
2. Now invoke the mysql client program by typing mysql at the prompt.
3. The prompt is changed to a mysql> prompt. Type:

create database employees;

(Note: The command ends with a semi-colon).
4. The MySQL server responds with something like:

Query OK, 1 row affected (0.00 sec)

5. This means that you have sucessfully created the database. Now, let’s see how many databases you have on your system. Issue the following command.

show databases;

The server responds with the list of databases.

+—————-+
| Database |
+—————-+
| employees |
| mysql |
| test |
+—————-+
3 rows in set (0.00 sec)

Here we have three databases, two created by MySQL during installation and our employees database.
6. To come back to the DOS prompt, type quit at the mysql prompt.

Creating MySQL database on Linux system

1. I assume that you are working from your account and not the root. Start a terminal session and become the superuser (Type su at the prompt and then enter the root password).
2. Now we’ll access the MySQL server. Type:

mysql -u root -p

The system prompts for the MySQL root password that you set up in Installing MySQL on Linux. (Note: This is not the Linux root password but the MySQL root password). Enter the password, which is not displayed for security reasons.
Once you are successfully logged in, the system prints a welcome message and displays the mysql prompt … something like

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

Type ‘help’ for help.

mysql>

3. Now we are ready for creating the employees database. Issue the command:

create database employees;

(Note: The command ends with a semi-colon)
4. An important point to note is that this database is created by the root and so will not be accessible to any other user unless permitted by the root. Thus, in order to use this database from my account (called Thiyag), I have to set the permissions by issuing the following command:

GRANT ALL ON employees.* TO Thiyag@localhost IDENTIFIED BY “eagle”

The above command grants my account (Thiyag@localhost) all the permissions on employees database and sets my password to eagle. You should replace Thiyag with your user name and choose an appropriate password.
5. Close the mysql session by typing quit at the prompt. Exit from superuser and come back to your account. (Type exit).
6. To connect to MySQL from your account, type:

mysql -u user_name -p

Type in the password when prompted. (This password was set by the GRANTS ALL… command above) . The system displays the welcome message once you have successfully logged on to MySQL. Here is how your session should look like:

[Thiyag@localhost Thiyag]$ mysql -u Thiyag -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3 to server version: 3.22.32

Type ‘help’ for help.

mysql>

7. Typing the command SHOW DATABASES; will list all the databases available on the system. You should get a display similar to:

mysql> SHOW DATABASES;
+—————-+
| Database |
+—————-+
| employees |
| mysql |
| test |
+—————-+
3 rows in set (0.00 sec)

8. Enter quit at the mysql> prompt to come out of the mysql client program.