Install MySQL on Linux

written by: Cornel Mindeva; article published: year 2008, month 01;


In: Root » Computers and technology » Servers » Install MySQL on Linux

Dutch French Spanish Portuguese Italian German Japanese Chinese Korean Russian Arabic Bookmark and Share this Article

This tutorial describes how to install MySQL on a Linux Server, using the Linux shell prompt. You can use this shell either on the Linux server itself or remotely through a Telnet session. You will need to be logged in as the Linux root user.

Downloading MySQL

Most recent Linux distributions come with a copy of MySQL included, although not installed. You can either use the distribution package to install or download the latest version of MySQL from the MySQL web site at http://www.mysql.com/downloads/index.html.

Next, select the following option:

MySQL 3.23 – Production release (recommended)

MySQL 3.23 is the current stable production version; the other versions are still experimental and are not recommended for a production server.

You are going to install the RPM version of MySQL, as it's comparatively easy and MySQL needs little initial configuration. RPM stands for Redhat Package Manager, and it automates most of the installation process.

Scroll down the page to the section labeled

Linux x86 RPM downloads

There are currently five files available here:

  • Server

  • Benchmark/test suites

  • Client programs

  • Libraries and header files

  • Dynamic client libraries

At the very least, you need to download the "Server" package. It's also recommended that you download the "Libraries and header files" and "Client programs" packages to allow other programs to link to MySQL. If you wish, you can also download the other packages, such as "Benchmark/test suites." You will notice that the filenames usually contain version numbers. You should make sure the packages you download are all for the same version, as mixing packages for different versions may cause problems.

Installing MySQL

You now need to use the Linux rpm program to install the RPM packages that you downloaded. Execute the following command to start the installation (remember this must be done as the root user):

rpm -ivh MySQL-3.23.55-1.i386.rpm  

Make sure you type the command exactly at it is above, with the same case, as Linux filenames are case sensitive.

Once you've started the command, MySQL will install and you should see output similar to the following:

Preparing...                    
###########################################  [100%]      
1:MySQL                     
###########################################  [100%]  
Preparing db table  
Preparing host table  
Preparing user table  
Preparing func table  
Preparing tables_priv table  
Preparing columns_priv table  
Installing all prepared tables  
030206 21:22:35 /usr/sbin/mysqld: 
Shutdown Complete
 PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !  
This is done with:  
/usr/bin/mysqladmin -u root password 'new-password'  
/usr/bin/mysqladmin -u root -h linux.localdomain password 'new-  password'  
See the manual for more instructions.    
Please report any problems with the /usr/bin/mysqlbug script!    
The latest information about MySQL is available on the web at  
http://www.mysql.com  
Support MySQL by buying support/licenses at https://order.mysql.com    
Starting mysqld daemon with databases from /var/lib/mysql  

This completes the MySQL installation. If you get any error messages, it's likely that your system lacks other packages that MySQL needs to install (the error messages should tell you which ones). Download and install these packages, then execute the rpm command again, and MySQL should then install successfully.

One of the nice things about the rpm command is that in future you can easily upgrade to a later version using the command

rpm -Uvh MySQL-latest-version.rpm  

The U command tells RPM to update the existing installation, which it does automatically.

Installing the MySQL Libraries and Header Files

It's a good idea to also install the MySQL "Libraries and header files," as other packages that you install in the future may need these so they can use and connect to MySQL.

Before you can install the "Libraries and header files" package (MySQL-devel-3.23.55-1.i386.rpm), you need to install the MySQL client files, which are in the package MySQL-client-3.23.55-1.i386.rpm. Once you have downloaded the files, you can install the package using the following command:

rpm -ivh MySQL-client-3.23.55-1.i386.rpm  

You should then see an output similar to the following:

Preparing...                    
###########################################  [100%]      
1:MySQL-client             
###########################################  [100%]  

The MySQL client files are now installed, and you can go on to install the development files. Execute the following command to install the package:

rpm -ivh MySQL-devel-3.23.55-1.i386.rpm  

You should then see output similar to the following:

Preparing...                    
###########################################  [100%]      
1:MySQL-devel               
###########################################  [100%]  

The MySQL development files are now installed.

Starting and Stopping the MySQL Server

When the MySQL RPM package is installed, it adds a start-up file to initiation files in the etc system directory. The full path is as follows:

/etc/rc.d/init.d/mysql  

This means that MySQL will start when the server boots up. You can also use this file to start and stop the server.

To start the MySQL server, you need to execute the following command:

/etc/rc.d/init.d/mysql start  

You should then see the following output:

Starting mysqld daemon with databases from /var/lib/mysql  

To stop the MySQL server, you need to execute the following command:

/etc/rc.d/init.d/mysql stop  

You should then see output similar to the following:

Killing mysqld with pid 10024  030206 22:17:04 mysqld ended  

MySQL File Locations

It's useful to be able to see where the RPM packages installed the files contained within them. To do this, you can use the command

rpm -ql PackageName  

where PackageName is the name of the installed package without file extensions. For example, look at the RPM file containing the MySQL files, which is called MySQL-devel-3.23.55-1.i386.rpm. Note, however, that some Linux distributions may use slightly different filenames. You can find the locations of its files with the command

rpm -ql MySQL-3.23.55-1  

You can see that the .i386.rpm extension is removed in the preceding command. This will output the location of the files that the package installed, a small snippet of which is as follows:

/etc/logrotate.d/mysql  
/etc/rc.d/init.d/mysql  
/usr/bin/isamchk  
/usr/bin/isamlog  
/usr/bin/my_print_defaults  
/usr/bin/myisamchk  
/usr/bin/myisamlog  
/usr/bin/myisampack  
/usr/bin/mysql_convert_table_format  
/usr/bin/mysql_fix_privilege_tables  
/usr/bin/mysql_install_db  
/usr/bin/mysql_setpermission  
/usr/bin/mysql_zap  
/usr/bin/mysqlbug  
/usr/bin/mysqld_multi  
/usr/bin/mysqldumpslow  
/usr/bin/mysqlhotcopy  
/usr/bin/mysqltest  
/usr/bin/pack_isam  
/usr/bin/perror  
/usr/bin/replace  
/usr/bin/resolve_stack_dump  
/usr/bin/resolveip  
/usr/bin/safe_mysqld  
/usr/lib/mysql/mysqld.sym  
/usr/sbin/mysqld  

The snippet on the previous page shows the locations of the main program files. The development files install to the following locations:

/usr/include/mysql  
/usr/lib/mysql  

These are the locations you specify to another program when you're compiling in MySQL support. If you are ever unsure of where a certain file has been installed, you can use the preceding process to find the file.

If you decide at any point that you want to uninstall MySQL, it's important that you do it using the rpm command if you used RPM to install the program rather than deleting the files manually, as you may miss some files. Uninstalling with the rpm command ensures that everything is correctly removed. You can use the following command to uninstall a package:

rpm -e packagename  

Although installing MySQL using an RPM is much easier, if you wish you can download and compile MySQL from source code yourself by downloading the source files from the MySQL web site. This allows you to optimize MySQL for your particular Linux configuration, although there is no real need for this on a testing server.

Disclaimer

1) E-articles is not responsible for the information contained by this article as well for any and all copyright infringements by authors and writers. E-articles is a free information resource. If you suspect this article for any copyright infringement, please read the terms of service and contact us to investigate the problem.
2) E-articles is not responsible for inaccuracies, falsehoods, or any other types of misinformation this article may contain and will not be liable for any loss or damage suffered by a user through the user's reliance on the information gained here.

link to this article