How to Install MySQL from binary tar in Linux or Unix


How to Install MySQL from binary tar in Linux or Unix

To install MySQL in UNIX like system(s) you can follow various approaches as you like it.
  -- Install MySQL using RPM packages.  
  -- Install MySQL using pre-compiled binary tar file in the format tar.gz  
  --Install MySQL by compiling it from source code.

Note : Make sure that all files related to MySQL Server are owned by proper user 
say owner(mysql) and group(mysql).

The last approach gives the maximum flexibility but also do require a lot of effort on your part.

In this article we are going to discuss the second approach that is Install MySQL using pre-compiled binary tar file in the format tar.gz

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. MySQL compressed tar file binary distributions have names of the form mysql-VERSION-OS.tar.gz, where VERSION is a number (for example, 5.6.13), 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.

So get the required binary compressed tar file for MySQL and let’s get started.

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,
sql-bench
sample configuration files, SQL for database installation


Note:
   The procedure that follows provides general guidelines for quick MySQL installation. You can read the related documentation for more options like :

            1) How to give a group and user a groupid and userid.
   2)How to edit my.cnf to place MySQL components like datadir, log, Innodb file etc. at different locations.

Create a MySQL User and Group that is responsible for running MySQL.

shell> groupadd mysql
shell> useradd -g mysql mysql

Move the compressed file to desired location, Uncompress and Unpack the MySQL to required location and create a Symbolic link on that.
(You can use the default location or can edit my.cnf later on)
(Assumption: mysql-VERSION-OS.tar.gz is in /usr/local)

shell> cd /usr/local
shell> tar –zxvf mysql-VERSION-OS.tar.gz

{
      gunzip < mysql-VERSION-OS.tar.gz | tar xvf –
(In place of above step, if tar does not support the z option.)  
}

shell> ln -s full-path-to-mysql-VERSION-OS mysql

Change the Group and Owner of the MySQL files to mysql:mysql (user:group)

shell> chown –R mysql:mysql /usr/local/mysql


shell> cd mysql

On Unix, the grant tables are set up by the mysql_install_db program. So next step is to run that script.

shell> scripts/mysql_install_db --user=mysql [--datadir=<value> if data directory is not at the default location]
(You can specify other parameters too.)

Create a my.cnf file at the default location or provide the –-defaults-file option while starting mysqld_safe.
(my.cnf is MySQL configuration file that allow you to set various properties of MySQL server under which it can run.)

shell> cp support-files/my-medium.cnf /etc/my.cnf
(Edit my.cnf as per your requirements.)

Start the MySQL Server Daemon.
shell> bin/mysqld_safe --user=mysql &

If you want MySQL to start automatically when you boot your machine, you can copy supportfiles/mysql.server to the location where your system has its startup files.

shell> cp support-files/mysql.server /etc/init.d/mysql
(Make sure that it is executable. (‘x’ is set))


shell> chmod +x /etc/init.d/mysql

After installing the script, the commands needed to activate it to run at system startup depend on your operating system. On Linux, you can use chkconfig:

shell> chkconfig --add mysql

On some Linux systems, the following command also seems to be necessary to fully enable the mysql script:

shell> chkconfig --level 345 mysql on

Secure the Initial MySQL installation

shell> bin/mysql_secure_installation
(The MySQL server must be running for this step to complete.)


Shutdown the Server if required.
shell> mysqladmin –u root –p shutdown
password:<supply mysql root password here>

You should add the path to MySQL bin directory in the PATH environment variable by setting it in mysql user profile or by some other way. Doing so you can run client programs etc. from anywhere and no need to set current working directory again and again.

Sample my.cnf file
 
[client]
port=3306
socket=/tmp/mysql.sock

[mysqld]
basedir==/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/var/tmp/mysql.sock
port=3306
user=mysql

Comments

Back To Top

Popular posts from this blog

error 18 at 0 depth lookup: self signed certificate

How to check fragmentation in MySQL tables

How to Drop or Remove or Decommission a Database in Oracle