Oracle provides a set of binary distributions of MySQL. These
include binary distributions in the form of compressed
tar files (files with a
.tar.gz extension) for a number of platforms,
as well as binaries in platform-specific package formats for
selected platforms.
This section covers the installation of MySQL from a compressed tar file binary distribution. For other platform-specific package formats, see the other platform-specific sections. For example, for Windows distributions, see Installing MySQL on Microsoft Windows.
To obtain MySQL, see How to Get MySQL.
MySQL compressed tar file binary distributions
have names of the form
mysql-,
where VERSION-OS.tar.gz is a
number (for example, VERSION5.5.33), and
OS indicates the type of operating system
for which the distribution is intended (for example,
pc-linux-i686 or winx64).
To install MySQL from a compressed tar file
binary distribution, your system must have GNU
gunzip to uncompress the distribution and a
reasonable tar to unpack it. If your
tar program supports the z
option, it can both uncompress and unpack the file.
GNU tar is known to work. The standard
tar provided with some operating systems is not
able to unpack the long file names in the MySQL distribution. You
should download and install GNU tar, or if
available, use a preinstalled version of GNU tar. Usually this is
available as gnutar, gtar, or
as tar within a GNU or Free Software directory,
such as /usr/sfw/bin or
/usr/local/bin. GNU tar is
available from http://www.gnu.org/software/tar/.
If you have previously installed MySQL using your operating system
native package management system, such as yum
or apt-get, you may experience problems
installing using a native binary. Make sure your previous MySQL
previous installation has been removed entirely (using your
package management system), and that any additional files, such as
old versions of your data files, have also been removed. You
should also check the existence of configuration files such as
/etc/my.cnf or the
/etc/mysql directory have been deleted.
If you run into problems and need to file a bug report, please use the instructions in How to Report Bugs or Problems.
On Unix, to install a compressed tar file binary
distribution, unpack it at the installation location you choose
(typically /usr/local/mysql). This creates the
directories shown in the following table.
Table 1.1. MySQL Installation Layout for Generic Unix/Linux Binary Package
| Directory | Contents of Directory |
|---|---|
bin | Client programs and the mysqld server |
data | Log files, databases |
docs | Manual in Info format |
man | Unix manual pages |
include | Include (header) files |
lib | Libraries |
scripts | mysql_install_db |
share | Miscellaneous support files, including error messages, sample configuration files, SQL for database installation |
sql-bench | Benchmarks |
Debug versions of the mysqld binary are available as mysqld-debug. To compile your own debug version of MySQL from a source distribution, use the appropriate configuration options to enable debugging support. For more information on compiling from source, see Installing MySQL from Source.
To install and use a MySQL binary distribution, the basic command sequence looks like this:
shell>groupadd mysqlshell>useradd -r -g mysql mysqlshell>cd /usr/localshell>tar zxvfshell>/path/to/mysql-VERSION-OS.tar.gzln -sshell>full-path-to-mysql-VERSION-OSmysqlcd mysqlshell>chown -R mysql .shell>chgrp -R mysql .shell>scripts/mysql_install_db --user=mysqlshell>chown -R root .shell>chown -R mysql data# Next command is optional shell>cp support-files/my-medium.cnf /etc/my.cnfshell>bin/mysqld_safe --user=mysql &# Next command is optional shell>cp support-files/mysql.server /etc/init.d/mysql.server
A more detailed version of the preceding description for installing a binary distribution follows.
This procedure assumes that you have root
(administrator) access to your system. Alternatively, you can
prefix each command using the sudo (Linux) or
pfexec (OpenSolaris) command.
The procedure does not set up any passwords for MySQL accounts. After following the procedure, proceed to Postinstallation Setup and Testing.
mysql User and Group
If your system does not already have a user and group for
mysqld to run as, you may need to create one. The
following commands add the mysql group and the
mysql user. You might want to call the user and
group something else instead of mysql. If so,
substitute the appropriate name in the following instructions. The
syntax for useradd and
groupadd may differ slightly on different
versions of Unix, or they may have different names such as
adduser and addgroup.
shell>groupadd mysqlshell>useradd -r -g mysql mysql
Because the user is required only for ownership purposes, not
login purposes, the useradd command uses the
-r option to create a user that does not have
login permissions to your server host. Omit this option to permit
logins for the user (or if your useradd does
not support the option).
Pick the directory under which you want to unpack the distribution
and change location into it. The example here unpacks the
distribution under /usr/local. The
instructions, therefore, assume that you have permission to create
files and directories in /usr/local. If that
directory is protected, you must perform the installation as
root.
shell> cd /usr/local
Obtain a distribution file using the instructions in How to Get MySQL. For a given release, binary distributions for all platforms are built from the same MySQL source distribution.
Unpack the distribution, which creates the installation directory.
Then create a symbolic link to that directory.
tar can uncompress and unpack the distribution if
it has z option support:
shell>tar zxvfshell>/path/to/mysql-VERSION-OS.tar.gzln -sfull-path-to-mysql-VERSION-OSmysql
The tar command creates a directory named
mysql-.
The VERSION-OSln command makes a symbolic link to that
directory. This enables you to refer more easily to the installation
directory as /usr/local/mysql.
If your tar does not have z
option support, use gunzip to unpack the
distribution and tar to unpack it. Replace the
preceding tar command with the following
alternative command to uncompress and extract the distribution:
shell> gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf -
The remainder of the installation process involves setting up the configuration file, creating the core databases, and starting the MySQL server. For instructions, see Postinstallation Setup and Testing.
The accounts that are listed in the MySQL grant tables initially have no passwords. After starting the server, you should set up passwords for them using the instructions in Postinstallation Setup and Testing.

User Comments
This step will be helpful in Installation of MySQL.One needs to follow additional step of changing the file ownership.
Even after executing following command as mentioned in the document:
chown -R mysql .
chgrp -R mysql .
There are four symbolic link files whose ownership is not changed(/usr/mysql/lib).
lrwxrwxrwx 1 7155 staff 24 Mar 9 06:28 libmysqlclient.so.16 -> libmysqlclient.so.16.0.0
lrwxrwxrwx 1 7155 staff 24 Mar 9 06:28 libmysqlclient.so -> libmysqlclient.so.16.0.0
lrwxrwxrwx 1 7155 staff 26 Mar 9 06:28 libmysqlclient_r.so.16 -> libmysqlclient_r.so.16.0.0
lrwxrwxrwx 1 7155 staff 26 Mar 9 06:28 libmysqlclient_r.so -> libmysqlclient_r.so.16.0.0
In order to change ownership of these files one needs to use following command.
chown -h mysql:mysql libmysqlclient.so.16 libmysqlclient.so libmysqlclient_r.so.16 libmysqlclient_r.so
The previous comment depends on which operating system you are using. I am running slackware w/ kernel 2.6.33.4-smp and I did not have to specifically rename the symbolic links.
On Ubuntu server 11.04, before running "mysql_install_db" you must be sure that "libaio" library is installed on you machine.
to install it use:
sudo apt-get install libaio
In CentOS 6 (the only version I have studied deeply so far) the following commands change the owner of all files (even hidden ones and symbolic links):
chown -R mysql .
chgrp -R mysql .
I did it in one step, though:
chown -R mysql:mysql .
So, despite the fact that Rohit Mahambre's comments might be helpful when using other distros, in CentOS 6 there is no need to use more commands.
This is the output of ls -la for my lib subdirectory:
[george@CentOS-6-host lib]$ ls -la
total 224776
drwxr-xr-x. 3 mysql mysql 4096 Dec 12 18:56 .
drwxr-xr-x. 13 mysql mysql 4096 Dec 12 18:59 ..
-rw-r--r--. 1 mysql mysql 14768868 Nov 23 10:32 libmysqlclient.a
lrwxrwxrwx. 1 mysql mysql 16 Dec 12 18:56 libmysqlclient_r.a -> libmysqlclient.a
lrwxrwxrwx. 1 mysql mysql 17 Dec 12 18:56 libmysqlclient_r.so -> libmysqlclient.so
lrwxrwxrwx. 1 mysql mysql 17 Dec 12 18:56 libmysqlclient_r.so.18 -> libmysqlclient.so
lrwxrwxrwx. 1 mysql mysql 17 Dec 12 18:56 libmysqlclient_r.so.18.0.0 -> libmysqlclient.so
lrwxrwxrwx. 1 mysql mysql 20 Dec 12 18:56 libmysqlclient.so -> libmysqlclient.so.18
lrwxrwxrwx. 1 mysql mysql 24 Dec 12 18:56 libmysqlclient.so.18 -> libmysqlclient.so.18.0.0
-rwxr-xr-x. 1 mysql mysql 6844990 Nov 23 10:32 libmysqlclient.so.18.0.0
-rw-r--r--. 1 mysql mysql 103358370 Nov 23 10:36 libmysqld.a
-rw-r--r--. 1 mysql mysql 104165746 Nov 23 10:26 libmysqld-debug.a
-rw-r--r--. 1 mysql mysql 9584 Nov 23 10:28 libmysqlservices.a
-rw-r--r--. 1 mysql mysql 997127 Nov 23 10:21 libtcmalloc_minimal.so
drwxr-xr-x. 3 mysql mysql 4096 Dec 12 18:55 plugin
Thanks Saulius, your tip definitely helped, but for xubuntu 12.10, before the mysql_install_db command it is:
sudo apt-get install libaio1
that needs to be run.
On Ubuntu 12-04 LTS, you will need to perform:
cp support-files/my-default.cnf /etc/mysql/my.cnf
instead of the step:
cp support-files/my-medium.cnf /etc/my.cnf
On Linux Mint 14, installation of libaio1 is also necessary
***********************************************************************
** Installing MySQL 5.6.10 on Linux Debian 6.0.7 Squeeze kernel 2.6.32
***********************************************************************
** For use on Small Business/Personal/VPS servers
*****************************************
** Linux Debian version commands
** you have to be root privileged user
----------------------------------------
command> cat /etc/debian_version
> 6.0.7
command> uname -sro
> Linux 2.6.32-5-686 GNU Linux (for 32-bit)
> Linux 2.6.32-5-amd64 GNU Linux (for 64-bit)
**********
** NOTES
**********
** I call MySQL server user "mysqler" instead of standard user "mysql" just to be sure I hand over correct installation and not leaving any thing for accidents to appear in future
** If you want to use "mysql" user simply change "mysqler" to "mysql"
** I will put all mysqld log, sock and pid files at one directory called log to ease access to them at one place
** I will use port 50050 instead of default 3066 so you can change it to your preferred port
** mysqld-server script contain optional stat|stop|restart|status|backup method to ease database service management
** you have to be root privileged user
***************************************************************************************************
** Remove any pre-installed old mysql files / libraries usually linux distros installs MySQL 5.1 **
***************************************************************************************************
rm -fR /etc/mysql
rm -fR /var/lib/mysql/mysql
rm -fR /var/lib/mysql
find -R / -name mysql*
find / -name mysql*
rm -fR /opt/mysql
find / -name mysql*
*******************************************
** Prerequisite Packages
*******************************************
** Optional updates
command> apt-get -y update
command> apt-get -y install gcc build-essential linux-headers-$(uname -r) dkms
---------------------------------------------------------
** Download MySQL Community Server 5.6.10 for Platform:
Debian Linux ver. 6.0 (x86, 32-bit), DEB 5.6.10 275.7M (mysql-5.6.10-debian6.0-i686.deb)
OR
Debian Linux ver. 6.0 (x86, 64-bit), DEB 5.6.10 283.5M (mysql-5.6.10-debian6.0-x86_64.deb)
---------------------------------------------------------
** Disable the write-back cache for mysql innodb
** Ref. http://dev.mysql.com/doc/refman/5.0/en/innodb-configuration.html => Caution section
** if install on VPS usually set this parameter correctly not need to this step
apt-get install hdparm
** run command to disable write-back
command> hdparm -W0 /dev/sda
----------------------------
apt-get install libaio1 => required by mysqld server
apt-get install p7zip-full => nice tool to backup database files after shutdown server for small servers
apt-get install nano => most easy linux editor save=ctrl+o exit=ctrl+x arrow-keys to move
apt-get install dos2unix => incase you edited file on windows and sent it to linux !
** Add MySQL User, -r option means mysqler is only a system account and can't login as a regular user
groupadd mysqler
useradd -r mysqler
** Install on Debian 64bit mysql-5.6.10-debian6.0-x86_64.deb or on Debian 32bit mysql-5.6.10-debian6.0-i686.deb
dpkg -i /path/to/mysql-5.6.10-debian6.0-x86_64.deb
** installed to /opt/mysql/server-5.6 or what ever path is
** TO ease the installation process I recommend over writing configuration file /opt/mysql/server-5.6/support-files/my-default.cnf with your pre-configured my.cnf file to be copied automatically later when running mysql_install_db script
**Over write CONFIG FILE
** copy my.cnf sample attached below to a file and save to use as follow
** note, install_db script reads only this my-default.cnf file and use it in appropriate position
** note, don't uncomment #socket=/opt/mysql/server5.6/log/mysqld.sock at both [client] [mysqld] till end of these steps
cp /path/to/my/config/file/my.cnf /opt/mysql/server-5.6/support-files/my-default.cnf
** create log dir to hold server logs -- these are not innodb logs
mkdir /opt/mysql/server-5.6/log
** create backup dir to hold database files backups
mkdir /opt/mysql/backup-5.6
** create cert dir to hold server ssl certificates
mkdir /opt/mysql/server-5.6/cert
** Ref. to create mysql SSL certificates certificate authority, server certificate and client certificate
** http://dev.mysql.com/doc/refman/5.6/en/ssl-connections.html
** http://dev.mysql.com/doc/refman/5.6/en/creating-ssl-certs.html
** copy cert files to cert directory
cp /path/to/certificates/directory/* /opt/mysql/server-5.6/cert
**Update environment var /etc/profile
nano /etc/profile
export MYSQL_HOME=/opt/mysql/server-5.6
export PATH=$PATH:$MYSQL_HOME/bin
export MANPATH=$MANPATH:$MYSQL_HOME/man
####################################################
# NOW YOU MUST LOG OUT THEN LOG IN TO UPDATE PATH
####################################################
#Install Database Files
/opt/mysql/server-5.6/scripts/mysql_install_db --user=mysqler > /path/to/revise/mysql_install_db/output/file.txt 2>&1
** revise that installation process has no [ERROR] and Check [Warning] and read final comments
nano /path/to/revise/mysql_install_db/output/file.txt
** ensure only mysqler the only one read/write database files
chown -R root:root /opt/mysql
chown -R mysqler:mysqler /opt/mysql/server-5.6/data
chown -R mysqler:mysqler /opt/mysql/server-5.6/log
chown -R mysqler:mysqler /opt/mysql/backup-5.6
** install service and start database
** copy the mysqld-server sample attached below to a file and save as follow
cp /file/to/mysqld-server /etc/init.d/mysqld-server
update-rc.d mysqld-server defaults
/etc/init.d/mysqld-server start
** optional Securing Database / preferred set root password and yes for all questions
/opt/mysql/server-5.6/bin/mysql_secure_installation
** stop server and edit socket path then start server again
/etc/init.d/mysqld-server stop
nano /opt/mysql/server-5.6/my.cnf
** uncomment #socket=/opt/mysql/database-5.6/log/mysqld.sock then click ctrl+o then Enter then ctrl+x
**start server again
/etc/init.d/mysqld-server start
** verify server is running up and responding to connections
mysql -P50050 -u root -p --prompt='Server mysql > '
Server mysql > show databases;
Server mysql > \s
--------------
mysql Ver 14.14 Distrib 5.6.10, for debian6.0 (x86_64) using EditLine wrapper
Connection id: 1
Current database:
Current user: root@localhost
SSL: Cipher in use is DHE-RSA-AES256-SHA
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.6.10-log MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /opt/mysql/server-5.6/log/mysqld.sock
Uptime: 17 sec
Threads: 1 Questions: 5 Slow queries: 0 Opens: 70 Flush tables: 1 Open tables: 63 Queries per second avg: 0.294
--------------
Server mysql > exit;
** make initial backup
/etc/init.d/mysqld-server status
/etc/init.d/mysqld-server stop
/etc/init.d/mysqld-server backup
ls -lh /opt/mysql/backup-5.6
** Congratulations !
************************************************
** Sample my.cnf file
************************************************
[client]
no-beep
#socket=/opt/mysql/server-5.6/log/mysqld.sock
port=50050
ssl=ON
ssl-cipher=DHE-RSA-AES256-SHA
ssl-ca=/opt/mysql/server-5.6/cert/ca-cert.pem
ssl-cert=/opt/mysql/server-5.6/cert/client-cert.pem
ssl-key=/opt/mysql/server-5.6/cert/client-key.pem
[mysql]
default-character-set=utf8
[mysqld]
#skip-host-cache
#skip-name-resolve
basedir=/opt/mysql/server-5.6
datadir=/opt/mysql/server-5.6/data
pid-file=/opt/mysql/server-5.6/log/mysqld.pid
port=50050
#socket=/opt/mysql/server-5.6/log/mysqld.sock
log_output=FILE
general_log=1
general_log_file=/opt/mysql/server-5.6/log/mysql.log
log_error=/opt/mysql/server-5.6/log/mysql.err
log_isam=/opt/mysql/server-5.6/log/mysql.isam
slow_query_log=1
slow_query_log_file=/opt/mysql/server-5.6/log/slow-query.log
character-set-server=utf8
log_bin=off
back_log=70
flush_time=0
join_buffer_size=128M
sort_buffer_size=8M
read_rnd_buffer_size=8M
max_allowed_packet=4M
default_storage_engine=InnoDB
default_tmp_storage_engine=MYISAM
max_connect_errors=100
open_files_limit=4110
table_definition_cache=1400
explicit_defaults_for_timestamp=true
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#inno_db configurations
innodb=ON
innodb_open_files=300
innodb_checksum_algorithm=0
innodb_stats_on_metadata=1
innodb_file_per_table=1
innodb_buffer_pool_size=256M
innodb_flush_log_at_trx_commit=1
innodb_lock_wait_timeout=50
innodb_rollback_on_timeout=ON
innodb_log_file_size=32M
innodb_log_buffer_size=64M
innodb_log_files_in_group=2
innodb_sort_buffer_size=8M
ssl=ON
ssl-cipher=DHE-RSA-AES256-SHA
ssl-ca=/opt/mysql/server-5.6/cert/ca-cert.pem
ssl-cert=/opt/mysql/server-5.6/cert/server-cert.pem
ssl-key=/opt/mysql/server-5.6/cert/server-key.pem
**************************************************
** Sample /etc/init.d/mysqld-server
**************************************************
#!/bin/bash
# /etc/init.d/mysqld-server
### BEGIN INIT INFO
# Provides: MySQL
# Required-Start: $local_fs $network
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: MySQL
# Description: MySQL 5.6.10 Daemon
### END INIT INFO
#Settings
USER_NAME=mysqler
SCRIPT_PATH=/opt/mysql/server-5.6/support-files/mysql.server
DATABASE_DIRECTORY=/opt/mysql/server-5.6/data
BACKUP_DIRECTORY=/opt/mysql/backup-5.6
DEFAULTS_FILE=/opt/mysql/server-5.6/my.cnf
MYSQL_PROCESS_FILE=/opt/mysql/server-5.6/log/mysqld.pid
is_mysql_running() {
if [ -f $MYSQL_PROCESS_FILE ]; then
echo mysql server is currently started
else
echo mysql server is currently stopped
fi
}
script_start() {
is_mysql_running
if [ ! -f $MYSQL_PROCESS_FILE ]; then
echo starting now...
su - -p -s /bin/sh $USER_NAME -c "$SCRIPT_PATH start --user=$USER_NAME"
fi
}
script_stop() {
is_mysql_running
if [ -f $MYSQL_PROCESS_FILE ]; then
echo stopping now...
su - -p -s /bin/sh $USER_NAME -c "$SCRIPT_PATH stop"
else
echo MySQL server have to be started first
fi
}
script_restart() {
if [ -f $MYSQL_PROCESS_FILE ]; then
script_stop
script_start
is_mysql_running
else
echo MySQL server have to be started first
fi
}
script_status() {
is_mysql_running
su - -p -s /bin/sh $USER_NAME -c "$SCRIPT_PATH status"
}
script_backup() {
is_mysql_running
if [ -f $MYSQL_PROCESS_FILE ]; then
echo stop server before running backup
else
echo backup started...
BACKUP_TIME=$(date +"%Y-%m-%d_%H-%M_%p")
BACKUP_FILE="$BACKUP_DIRECTORY/$BACKUP_TIME.7z"
su - -p -s /bin/sh $USER_NAME -c "7z a $BACKUP_FILE $DATABASE_DIRECTORY"
echo backup finished...
fi
}
#Start-Stop here
case "$1" in
start)
script_start
;;
stop)
script_stop
;;
restart)
script_restart
;;
status)
script_status
;;
backup)
script_backup
;;
*)
echo "Usage: $0 {start|stop|restart|status|backup}"
exit 1
;;
esac
exit 0
Add your own comment.