Installing MySQL on Linux
Joel Philip on 2002 July 17
Joel Philip on 2002 July 17
This tutorial will go over the basics of installing MySQL for Linux. You will also learn how to start the MySQL server, create a database, create a table, fill the table with data, and view its contents
.Note: You must have root privileges to accomplish this installation!!
The recommended way to install MySQL on Linux is by using an RPM (Red Hat Package Manager) file. The MySQL RPMs are currently being built on a RedHat Version 6.2 system but should work on other versions of Linux that support RPM and use glibc.
The RPM files you may probably want to use are:
1) MySQL-VERSION.i386.rpm
The MySQL server. You will need this unless you only want to connect to a MySQL server running on another machine.
2) MySQL-client-VERSION.i386.rpm
The standard MySQL client programs. You probably always want to install this package.
3) MySQL-bench-VERSION.i386.rpm
Tests and benchmarks. Requires Perl and msql-mysql-modules RPMs.
4) MySQL-devel-VERSION.i386.rpm
Libraries and include files needed if you want to compile other MySQL clients, such as the Perl modules.
5) MySQL-VERSION.src.rpm
This contains the source code for all of the above packages. It can also be used to try to build RPMs for other architectures (for example, Alpha or SPARC).
To see all files in an RPM package, run:
shell> rpm -qpl MySQL-VERSION.i386.rpm
To perform a standard minimal installation, run:
shell> rpm -i MySQL-VERSION.i386.rpm MySQL-client-VERSION.i386.rpm
To install just the client package, run:
shell> rpm -i MySQL-client-VERSION.i386.rpm
The RPM places data in /var/lib/mysql. The RPM also creates the appropriate entries in /etc/rc.d/ to start the server automatically at boot time. (This means that if you have performed a previous installation, you may want to make a copy of your previously installed MySQL startup file if you made any changes to it, so you don't lose your changes.)
After when you have finished installing the RPM file(s), the mysqld daemon should be running and you should now be able to start using MySQL.
To start working with MySQL, use the command at the shell prompt:
shell>mysql
Welcome to the MySQL monitor. Commands end with; or g. Your
MySQL connection id is 1 to server version: 3.23.51
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
You are now in the MySQL Monitor and ready run your commands.
To view all of the available databases, enter:
mysql> SHOW DATABASES;
The system will display:
+----------+
| Database |
+----------+
| mysql |
| test |
+----------+
2 rows in set (0.14 sec)
To get started using a database, pick the database of choice. By default, there are two databases to choose from, one named mysql and the other named test. To get started using a particular database, you must select it.
Run the following command to use the "test" database.
mysql>USE test;
If you would like to create your own database then run the commands:
mysql> CREATE DATABASE newDB;
Query OK, 1 row affected (0.00 sec)
mysql> SHOW DATABASES;
+----------+
| Database |
+----------+
| mysql |
| newDB |
| test |
+----------+
3 rows in set (0.00 sec)
So, let's get started.
mysql> USE newDB;
Database changed
Because you're using the newDB database, we you can create a table to fill it with information.
Let's create a simple table; we will call it mydata. Copy and paste the following code into the MySQL Monitor.
CREATE TABLE mydata (
id int not null auto_increment primary key,
name varchar(25) not null
);
This creates a table called mydata and then we insert our information.
Copy and paste the following data into your MySQL Monitor:
INSERT INTO mydata (id,name) VALUES (NULL,"John");
INSERT INTO mydata (id,name) VALUES (NULL,"Paul");
INSERT INTO mydata (id,name) VALUES (NULL,"George");
INSERT INTO mydata (id,name) VALUES (NULL,"Ricky");
This inserts the information into our tables and it's ready to be viewed.
Let's view the contents of our table, named mydata using the SELECT command.
mysql> SELECT * FROM mydata;
+----+--------+
| id | name |
+----+--------+
| 1 | John |
| 2 | Paul |
| 3 | George |
| 4 | Ricky |
+----+--------+
4 rows in set (0.01 sec)
You learned how to do the following:
1. Install MySQL for Linux
2. Start up the MySQL server
3. Create a database
4. Use a database
5. Create a table
6. Insert data into a table
7. Select and view everything from your table
This is a good start for learning how to interact with the MySQL server. There are many aspects of the server to learn but you must know the basics in order to fully appreciate its speed and power. Take time to learn some new commands and what they accomplish. It will give you an understanding of what MySQL and SQL are all about and best of all, have fun!
View the links below for more information on MySQL and SQL.
http://www.mysql.com download MySQL
http://www.mysql.com/documentation/ MySQL documentation
http://www.sqlcourse.com an online interactive course in SQL
http://www.onlamp.com/onlamp/general/mysql.csp site dedicated to MySQL
http://www.onlamp.com/pub/q/aboutSQL site dedicated to SQL
