Install MySQL on Linux

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


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

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.

legal disclaimer

1) Our website 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 infringements, please read the Terms of service and contact us to investigate the problem.
2) The E-articles directory team is not responsible for inaccuracies, falsehoods, or any other types of misinformation this tutorial 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. Please read the Terms of service

Useful tools and features

Translate this article to...    Send this article to you or to a friend

Link to this article from your page   
If you like this article (tutorial), please link to it from your web page using the information above. Linking to this page, this is the only way to help us improve our service, the same time providing your visitors with a way to improve their online experience.

related articles

1. Configuring Exchange Server 2007 for Maximum Performance and Reliability
After decisions have been made about AD design, Exchange server placement, and client access, optimization of the Exchange server itself helps ensure efficiency, reliability, and security for the messaging platform. Designing an Optimal Operating System Configuration for Exchange As previously mentioned, Exchange Server 2007 only operates on the Windows Server 2003 operating system, and is scheduled to be able to run on the next version of the Windows Server operating system, currently referred to as Windows L...

2. Managing Identity Information Between LDAP Directories and Exchange Server 2007
LDAP directories are commonplace today and can be found in many business environments. UNIX applications in particular make wide use of the LDAP standard for directories. Along with this proliferation of LDAP directory structures comes a need to synchronize the information contained within them to an Exchange 2007 environment. The Enterprise version of MIIS 2003 contains MAs that support synchronization to LDAP directories. Consequently, a good understanding of LDAP concepts is required before syncing between the environments. ...

3. Understanding DNS Requirements for Exchange Server 2007
In Active Directory, all client logons and lookups are directed to local domain controllers and GC servers through references to the SRV records in DNS. Each configuration has its DNS and resource requirements. Exchange relies on other servers for client authentication and uses DNS to find those servers. In an Active Directory domain controller configuration, on the other hand, the Exchange server also participates in the authentication process for Active Directory. Using DNS in Exchange Server 2007 As has bee...

4. Securing and Maintaining an Exchange Server 2007 Implementation
One of the greatest advantages of Exchange Server 2007 is its emphasis on security. Along with Windows Server 2003, Exchange Server 2007 was developed during and after the Microsoft Trustworthy Computing initiative, which effectively put a greater emphasis on security over new features in the products. In Exchange Server 2007, this means that the OS and the application were designed with services “Secure by Default.” With Secure by Default, all nonessential functionality in Exchange must be turned on if needed. Thi...

5. Improvements in Exchange Server 2007 Relative to Security and Compliance
One of the improvement goals Microsoft has had with all of their products over the past few years has been to constantly improve the security in the products. More recently with all of the regulatory compliance laws and policies being implemented, Microsoft has focused a lot of security enhancements to address privacy, information archiving, and compliance support. The release of Exchange 2007 was no different—Microsoft added in several new enhancements in the areas of security and compliance support. One of the addition...

6. Designing Exchange Infrastructure
After Active Directory and the physical OS has been chosen and deployed, the Exchange infrastructure can be set up and optimized for the specific needs of the organization. With these needs in mind, you can do several things to optimize an Exchange 2007 setup, as detailed in the following sections. Determining the Exchange Version When installing Exchange, the choice of Exchange version needs to be made. As with Windows Server 2003, there are two versions of Exchange, Standard and Enterprise. The Standard Edit...

7. Synchronizing Exchange Server 2007 with Novell eDirectory
Novell eDirectory and Novell Directory Service (NDS) environments are relatively commonplace in business environments, and there is often a need to integrate them into deployed Exchange infrastructures. Several tools exist that can make this a reality, including the MIIS 2003 tools discussed. In addition, tools in the Microsoft-supplied Services for NetWare can be used to synchronize directory information between the two directory systems. NOTE Exchange 2000 Server and Exchange Server 2003 included a GroupWise ...

8. Integrating Client Access into Exchange Server 2007 Design
Although the Exchange server is a powerful systems component, it is only half the equation for an email platform. The client systems comprise the other half, and are a necessary ingredient that should be carefully determined in advance. Outlining Client Access Methods Great effort has been put into optimizing and streamlining the client access approaches available in Exchange 2007. Not only have traditional approaches such as the Outlook client been enhanced, but support for nontraditional access with POP3 and...

9. Domain Name System and Its Role in Exchange Server 2007
For computer systems to communicate with each other, whether you are talking about a local area network (LAN), a wide area network (WAN), or the Internet, they must have the ability to identify one another using some type of name resolution. Several strategies have been developed over the years, but the most reliable one to date (and the current industry standard) is the use of a DNS. Accurate name resolution is critical in a mail environment as well. For a message to reach its destination, it might pass through several syste...