Friday, February 14, 2014

MySQL Binary Installation on Ubuntu

                                    MySQL Binary Installation on Ubuntu

                 Created By : Amit Gera DBA(MySQL & ORACLE)
Goal:MySQL Standard Binary Installation on Ubuntu 64 bit through package

Partition Requirement:-
/mysql_admin:-Will contains mysql binaries and confirguration file
/mysql_backup:-Will contains mysql backup [i.e dumpfile or export files or import files]
/mysql_data:- Will contains data files
/mysql_home:-Will contains profiles , sql scripts etc
/mysql_logs:- Will contains log files [i.e trace ,alert , binary , slow query & general audit logfiles]



Note:-Here I have use name amit wrt service name ,As per guidelines we must set it to meaningful name i.e product service name

Prerequisites:-http://myora-dba-notes.blogspot.in/2014/03/mysql-distribution-formats.html

#~~#Step 1:-Download mysql packages for ubuntu
a.Create downloading destination directory
cmd:-mkdir -p /mysql_admin/mysql_binaries/download
b.Start Downloading at destination directory
If internet is available then use this cmd:-
wget -O /mysql_admin/mysql_binaries/download/mysql-5.6.16.deb http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.16-debian6.0-x86_64.deb
Else download this from other sources and copy here

#~~#Step 2:-
a.Create group and create user in that group for mysql
cmd:-
groupadd mysql_grp
useradd -r -g mysql_grp mysql_user
b.Create directory mention in below configuration file of step 5
cmd:-
mkdir -p /mysql_data/ibtablespace/
mkdir -p /mysql_data/datadir/
mkdir -p /mysql_data/iblogs
mkdir -p /mysql_logs/slow_logs/
mkdir -p /mysql_logs/error_log
mkdir -p /mysql_logs/replication_log
mkdir -p /mysql_logs/mytmp/
chown mysql_user.mysql_grp -R /mysql_data/
chown mysql_user.mysql_grp -R /mysql_logs/
c.Create configuration & binary directories
mkdir -p /mysql_admin/configuration_file
touch /mysql_admin/configuration_file/my.cnf
mkdir /mysql_admin/mysql_binaries/mysqlbinaries-5.6.16

#~~#Step 3:-Add following below listed entries into environment file and load it in envrinoment
step a. cmd:-
echo "PATH="$PATH:/mysql_admin/mysql_binaries/mysqlbinaries-5.6.16/opt/mysql/server-5.6/bin"" >> /etc/environment
echo "myadmin="/mysql_admin/"" >> /etc/environment
echo "basedir="/mysql_admin/mysql_binaries/mysqlbinaries-5.6.16"" >> /etc/environment
echo "myconf="/mysql_admin/configuration_file"" >> /etc/environment
echo "MYSQL_HOME="/mysql_home/homedir"" >> /etc/environment
echo "myadmin_download="/mysql_admin/mysql_binaries/download"" >> /etc/environment
step b. Run the file with cmd:-source /etc/environment

#~~#Step 4:- Install the package with command dpkg -i package-file-name
cmd:- dpkg -i --instdir=$basedir $myadmin_download/mysql-5.6.16.deb

#~~#Step 5:-
a.Check package is installed or not by command dpkg -l | grep 'keywork to be matched'
cmd:- dpkg -l | grep 'libaio1' or dpkg -l \*libaio1\*
Note:- Package information is stored in File Name /var/lib/dpkg/status
b.Install package if not present
cmd:-apt-get install libaio1

#~~#Step 6: Create configuration file
a. vi /mysql_admin/configuration_file/my.cnf
b. write below listed information into configuration file and save
[client]
port = 3310
socket = /mysql_data/my_amit.sock
# The MySQL server
[mysqld]
user=mysql_user
port = 3310
socket = /mysql_data/my_amit.sock
basedir=/mysql_admin/mysql_binaries/mysqlbinaries-5.6.16/opt/mysql/server-5.6
pid-file =/mysql_data/my_amit.pid
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
tmpdir=/mysql_logs/mytmp/
datadir=/mysql_data/datadir/
innodb_data_home_dir = /mysql_data/ibtablespace/
innodb_mirrored_log_groups=1
innodb_log_group_home_dir = /mysql_data/iblogs
innodb_log_files_in_group=3
innodb_log_file_size=256M
log-bin = /mysql_logs/replication_log/amit-replication
log-error = /mysql_logs/error_log/amit-mysqllog.err
slow_query_log=on
long_query_time=1
slow_query_log_file=/mysql_logs/slow_logs/amit-master-slow.log
default-storage-engine = innodb
innodb_file_per_table

#~~#Step 7:- Now we have to initializes the MySQL data directory and creates the system tables that it should contains.
cmd:-
cd $basedir/opt/mysql/server-5.6/
scripts/mysql_install_db --user=mysql_user --basedir=/mysql_admin/mysql_binaries/mysqlbinaries-5.6.16/opt/mysql/server-5.6 --defaults-file=/mysql_admin/configuration_file/my.cnf

Note: option user=mysql_user is used in order to initialized db with ownership mysql user

There are some third party tool which can help you in creation or tunning of configuration files with respect to inputs mentiones
URL for Percona Configuration Wizard for MySQL is :-https://tools.percona.com/ or https://tools.percona.com/wizard


#~~#Step8: There are many ways by which we can start mysql and here we invoke mysql.server script method that use System V-style run directories (that is, /etc/init.d and run-level specific directories),
##Generally, you start the mysqld server in one of these ways:
a.Invoke mysqld directly. This works on any platform.
b.Invoke mysqld_safe, which tries to determine the proper options for mysqld and then runs it with those options. This script is used on Unix and Unix-like systems.
c.Invoke mysql.server. This script is used primarily at system startup and shutdown on systems that use System V-style run directories (that is, /etc/init.d and run-level specific directories), where it usually is installed under the name mysql. The mysql.server script starts the server by invoking mysqld_safe.
d.On Mac OS X, install a separate MySQL Startup Item package to enable the automatic startup of MySQL on system startup. The Startup Item starts the server by invoking mysql.server.
e.Use the Solaris/OpenSolaris service management framework (SMF) system to initiate and control MySQL startup.

After initializing db ,Now we are proceding to add service in System V-style run directories

Execution steps:-
a.Copy server script and add in system V-style run directories
cmd:-
cp /mysql_admin/mysql_binaries/mysqlbinaries-5.6.16/opt/mysql/server-5.6/support-files/mysql.server /etc/init.d/mysql_amit_service
b.Optional if there is any old services which we need to remove :-
cmd:-update-rc.d -f old_mysql_service_name remove
c. Adding system startup for /etc/init.d/mysql_amit_service ...
cmd:-update-rc.d mysql_amit_service defaults

#~~#Step 9:- update socket in mysql_config
cmd:-
mysql_config_editor set --socket=/mysql_data/my_amit.sock

#~~#Step 10:
ln -s /mysql_admin/configuration_file/my.cnf /etc/my.cnf

#~~#Step 11: Now you can start mysql with
/etc/init.d/mysql_amit_service start
or
/etc/init.d/mysql_amit_service start

Note: We can Shutdown with
/etc/init.d/mysql_amit_service stop
or
/etc/init.d/mysql_amit_service stop



No comments:

Post a Comment