Installing MySQL From The Source
Installing MySQL From The Source
Installing MySQL From The Source
Objectives:
• Give the students a guide through MySQL’s installation and configuration process
Concepts
The source installation process is indeed somewhat more complicated than installing binaries or
packages. For starters, you should possess at least rudimentary knowledge of how to use build tools like
GNU gcc and make and you should have them installed on your operating system.
MySQL will let you dig your own grave in the sense that passwords such as 123, abc and your
mother’s name are all perfectly acceptable. Choosing a password that is at least eight characters long
and consists of a combination of numeric and alphabetical characters of varying case.
Failing to setup an administrator password means that anybody with access to the operating
system can shut down the daemon not to mention completely destroy your database server and its
data.
The script responsible for starting the MySQL daemon is called mysqld_safe, which is located in
the INSTALL-DIR/bin. This script can only be started by a user possessing sufficient execution privileges,
typically either root or a member of the group mysql.
Keep in mind that mysqld_safe will not execute unless yo first change to the INSTALL-DIR
directory. In addition, the trailing ampersand is required, because you’ll want the daemon to run in the
background.
The mysqld_safe script is actually a wrapper around the mysqld server daemon, offering
features that are not available by calling mysqld directly such as run-time logging and automatic restart
in case of error.
Linux is capable of operating system in several different system states, each of which is defined
by the set of services made available to the user when the state is in control of the system. Each such
runlevels are available, although typically only seven are of interest to the user.
Runleve Description
l
0 Halt
1 Single-user Mode
2 Empty (user-definable)
4 Empty (user-definable)
5 Full multiuser mode (with windowing)
6 Reboot
Whether and in what order services are started or terminated within each runlevel is
determined by examining the first three characters of each symbolic link found in the respective
runlevel folder. If the symbolic link begins with an S, that service will be initiated in that runlevel. If it
begins with a K, it will be terminated. The two-digit integer following this first character determines the
order in which that service will be initiated or terminated. The higher the number, the later its fate will
be addressed.
The mysqld_safe wrapper adds a few extra safety-related logging features and system-integrity
features to the picture when the daemon is started. Given these useful features, myqld_safe is the
preferred way to start the server, although you should keep in mind that it’s only a wrapper and should
not be confused with the server itself.
Literally hundreds of MySQL server configuration options are at your disposal, capable of fine-
tuning practically every conceivable aspect of the daemon’s operation, including MySQL’s memory
usage, logging sensitivity and boundary settings such as maximum number of simultaneous connections,
temporary tables and connection errors among others.
A well-tuned MySQL server is capable of working with many connections simultaneously. Each
connection must be received and delegated to a new thread by the main MySQL thread, a task that
although trivial, isn’t instantaneous. The back_log parameter determines the number of connections
that are allowed to queue up while this main thread deals with a particularly heavy new connection
load. By default this is set to 50.
Keep in mind that you can’t just set this to a very high value and assume it will make MySQL run
more efficiently. Both your operating system and Web server may have other maximum settings in place
that could render a particular high value irrelevant.
By default, MySQL communicates in port 3306; however, you can reconfigure it to listen on any
other port by using the port parameter.
Enabling the skip-name-resolve parameter prevents MySQL form resolving hostnames. This
means that all Host column values in the grant tables consist either of an IP address or localhost. If you
plan to use solely IP addresses or localhost, enable this parameter.
Limiting Connections
Enabling the skip-networking parameter prevents MySQL from listening for TCP/IP connections, a wise
idea if your MySQL installation resides on the same server from which you’ll be initiating connections.
The MySQL daemon should run as a non-root user, minimizing the damage if an attacker were
to ever successfully enter the server via a MySQL security hole. Although the common practice is to run
the server as a user mysql, you can run it as any existing user provided that the user is the owner of the
data directories.
Configuration changes can be made on the command line when starting the MySQL daemon via
its wrapper , mysqld_safe. However, there exists a much more convenient method for tweaking the
startup parameters as well as the behaviors opf may MySQL clients. You can maintain these tweaks
within MySQL configuration file, my.cnf.
At startup, MySQL looks in several directories for the my.cnf file with each directory determining
the scope of the parameters declared within. The location and relative scope of each directory is
highlighted below:
• /etc/my.cnf
Global configuration file.
All MySQL server daemons located in the server refer first to this file.
• DATADIR/my.cnf
Server-specific configuration.
This file is placed in the directory by the server installation. A somewhat odd, yet crucial
characteristic of this configuration file is that it references only the data directory specified at
the configuration time even if a new data directory is specified at run time.
Procedures:
root@AMD64:/home/sysadmin# cd /usr/src
root@AMD64:/home/sysadmin# tar -xvzf mysql-VERSION.tar.gz
root@AMD64:/home/sysadmin# cd mysql-VERSION
5. Configure, make and install MySQL. A C++ compiler and make program are required. Using
recent versions of GNU gcc and make programs is strongly recommended. Keep in mind that –
OTHER-CONFIGURATION_FLAGS is a placeholder for any configuration settings that determine
several important characteristics of the MySQL server such as installation directory location. It is
left to you to decide which flags best suit your special needs.
6. Copy the MySQL configuration file (my.cnf) into its typical location and set its ownership.
7. Install the MySQL database. Mysql_install_db is a shell script that logs in to the MySQL database
server, creates all of the necessary tables and populates them with initial values.
9. Logout root.
root@AMD64:/home/sysadmin# exit
Starting MySQL
1. The following command is used to start MySQL
sysadmin@AMD64:~$ cd INSTALL-DIR
sysadmin@AMD64:~$ ./bin/mysqld_safe - -user=mysql &
sysadmin@AMD64:~$ cd INSTALL-DIR/bin
sysadmin@AMD64:~$ mysqladmin –u root password ‘new password’
Stopping MySQL
1. The process of stopping MySQL server is as follows:
sysadmin@AMD64:~$ cd INSTALL-DIR/bin
sysadmin@AMD64:~$ mysqladmin -u root -p shutdown
Enter password: ********