Database Journal
MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Tips Database Forum Rss Feed

» Database Journal Home
» Database Articles
» Database Tutorials
MS Access
SQL Scripts & Samples
» Database Forum
» Slideshows
Free Newsletters:

News Via RSS Feed

Rss Feed

Database Journal |DBA Support |SQLCourse |SQLCourse2

Featured Database Articles


Posted Jan 3, 2002

Installing MySQL (Under Linux) - Page 6

By Kevin Yank

MySQL is freely available for Linux from http://www.mysql.com (or one of its mirrors listed at http://www.mysql.com/downloads/mirrors.html). Download the latest stable release (listed as "recommended" on the download page). You should grab the "Tarball" version under "Source downloads", with filename mysql-3.xx.xx.tar.gz.

With the program downloaded (it was about 10.5MB as of this writing), you should make sure you're logged in as root before proceeding with the installation, unless you only want to install MySQL in your own home directory. To begin, unpack the downloaded file and move into the directory that is created:

% tar xfz mysql-3.xx.xx.tar.gz
% cd mysql-version

Next, you need to configure the MySQL install. Unless you really know what you're doing, all you should have to do is tell it where to install. I recommend /usr/local/mysql:

% ./configure --prefix=/usr/local/mysql

After sitting through the screens and screens of configuration tests, you'll eventually get back to a command prompt. Be sure the configuration completed successfully. If you see an error message just before the configuration quit, you'll need to address the problem it's complaining about. On Mandrake 8.0, for example, it complained of "No curses/termcap library found". I simply installed the 'libncurses5-devel' package in Mandrake's Software Manager, and the configuration worked fine on a second attempt. Once configuration is complete, you're ready to compile MySQL:

% make

After even more screens of compilation (this could take as long as a half an hour on some systems), you'll again be returned to the command prompt. You're now ready to install your newly compiled program:

% make install

MySQL is now installed, but before it can do anything useful its database files need to be installed too. Still in the directory you installed from, type the following command:

% scripts/mysql_install_db

With that done, you can delete the directory you've been working in, which just contains all the source files and temporary installation files. If you ever need to reinstall, you can simply re-extract the mysql-version.tar.gz file.

With MySQL installed and ready to store information, all that's left is to get the server running on your computer. While you can run the server as the root user, or even as yourself (if, for example, you installed the server in your own home directory), the best idea is to set up on the system a special user whose sole purpose is to run the MySQL server. This will remove any possibility of someone using the MySQL server as a way to break into the rest of your system. To create a special MySQL user, you'll need to log in as root and type the following commands:

% /usr/sbin/groupadd mysqlgrp
% /usr/sbin/useradd -g mysqlgrp mysqlusr

By default, MySQL stores all database information in the var subdirectory of the directory to which it was installed. We want to make it so that nobody can access that directory except our new MySQL user. Assuming you installed MySQL to the /usr/local/mysql directory, use these commands:

% cd /usr/local/mysql
% chown -R mysqlusr.mysqlgrp var
% chmod -R go-rwx var

Now everything's set for you to launch the MySQL server for the first time. From the MySQL directory, type the following command:

% bin/safe_mysqld --user=mysqlusr &

If you see the message 'mysql daemon ended', then the MySQL server was prevented from starting. The error message should have been written to a file called hostname.err (where hostname is your machine's hostname) in MySQL's var directory. You'll usually find that this happens because another MySQL server is already running on your computer.

If the MySQL server was launched without complaint, the server will run (just like your Web or FTP server) until your computer is shut down. To test that the server is running properly, type the following command:

% bin/mysqladmin -u root status

A little blurb with some statistics about the MySQL server should be displayed. If you receive an error message, something has gone wrong. Again, check the hostname.err file to see if the MySQL server output an error message while starting up. If you retrace your steps to make sure you followed the process described above, and this doesn't solve the problem, a post to the SitePoint.com Forums will help you pin it down in no time.

If you want your MySQL server to run automatically whenever the system is running (just like your Web server probably does), you'll have to set it up to do so. In the share/mysql subdirectory of the MySQL directory, you'll find a script called mysql.server that can be added to your system startup routines to do this.

First of all, assuming you've set up a special MySQL user to run the MySQL server, you'll need to tell the MySQL server to start as that user by default. To do this, create in your system's /etc directory a file called my.cnf that contains these two lines:


Now, when you run safe_mysqld or mysql.server to start the MySQL server, it will launch as mysqlusr without your having to tell it to. All that's left to do is to set up your system to run mysql.server automatically at startup.

Setting up your system to run the script at startup is a highly operating system-dependant task. If you're not sure of how to do this, you'd be best to ask someone who knows. However the following commands (starting in the MySQL directory) will do the trick for most versions of Linux:

% cp share/mysql/mysql.server /etc/rc.d/init.d/
% cd /etc/rc.d/init.d
% chmod 500 mysql.server
% cd /etc/rc.d/rc3.d
% ln -s ../init.d/mysql.server S99mysql
% cd /etc/rc.d/rc5.d
% ln -s ../init.d/mysql.server S99mysql

NOTE: Under the current SUSE distribution of Linux, there is no init.d directory, just a symbolic link pointing back to /etc/rc.d; symbolic links for startup files should thus be directed to the /etc/rc.d directory (e.g. ln –s ../mysql.server S99mysql).

That's it! To test that this works, reboot your system and request the status of the server as before.

One final thing you might like to do for convenience sake, is to place the MySQL client programs, which you'll use to administer your MySQL server later on, in the system path. To this end, you can place symbolic links to mysql, mysqladmin, and mysqldump in your /usr/local/bin directory:

% ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql
% ln -s /usr/local/mysql/bin/mysqladmin /usr/local/bin/mysqladmin
% ln -s /usr/local/mysql/bin/mysqldump /usr/local/bin/mysqldump

MySQL Archives

Latest Forum Threads
MySQL Forum
Topic By Replies Updated
MySQL in high availability and transction secure banking application klamor 1 August 28th, 10:24 AM
MySQL rollback UAL225 1 August 28th, 10:15 AM
Browsing a DB file that uses MySql finleytech 1 July 26th, 10:51 AM
php cookie won't pass variable to next page ITdevGirl 0 June 22nd, 12:13 PM