MySQL 5.5 Source Installation - Cmake (Multiple Instances)

Keywords: MySQL cmake socket yum

1. Environment

OS environment: Linux db01 2.6.32-431.el6.i686
 MySQL version: mysql-5.5.44
 MySQL installation path: /usr/local/mysql
 MySQL data path: /data
 MySQL port: 3506 3507

2. Preparations

1. Dependent Package Installation

 yum install ncurses-devel libaio-devel gcc gcc-c++ bison -y

2. Install compiler software

yum install cmake -y

3. Create an administrative user

useradd mysql -s /sbin/nologin -M

4. Unpack

mkdir /app
cd /app && tar mysql-5.5.44.tar.gz
cd mysql-5.5.44

3. MySQL Installation

1. Cmake compilation

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=gbk,gb2312,utf8,ascii \
-DENABLED_LOCAL_INFILE=1 \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITHOUT_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FAST_MUTEXES=1 \
-DWITH_ZLIB=bundled \
-DWITH_READLINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_DEBUG=0 

2. install (longer time)

  make && make install && cd ..

3. Profile

mkdir /data/{3506,3507}/data -p && cd /data
touch my.cnf mysqld

(1) Edit the configuration file VIMMy.cnf

[client]
port        = 3507                        # Note the distinction from 3506 instances
socket      = /data/3507/mysql.sock

[mysqld]
port        = 3507
socket      = /data/3507/mysql.sock
basedir = /usr/local/mysql
datadir = /data/3507/data
open_files_limit = 1024
back_log = 600
max_connections = 800
max_connect_errors = 3000
table_cache = 614
external-locking = FALSE
max_allowed_packet = 8M
sort_buffer_size = 1M
join_buffer_size = 1M
thread_cache_size = 100
thread_concurrency = 2
query_cache_size = 2M
query_cache_limit = 1M
query_cache_min_res_unit = 2k
thread_stack = 192k
tmp_table_size = 2M
max_heap_table_size = 2M
long_query_time = 1
pid-file = /data/3507/mysqld.pid
log-bin = /data/3507/mysqld-bin
relay-log = /data/3507/relay-bin
relay-log-info-file = /data/3507/relay-log.info
expire_logs_days = 7
key_buffer_size = 16M
read_buffer_size = 1M
read_rnd_buffer_size = 1M
bulk_insert_buffer_size = 1M
lower_case_table_names = 1
skip-name-resolve
slave-skip-errors = 1032,1062
replicate-ignore-db = mysql

server-id   = 3                       # Note the distinction from 3506 instances

innodb_additional_mem_pool_size = 4M
innodb_buffer_pool_size = 32M
innodb_data_file_path = ibdata1:128M:autoextend
innodb_file_io_threads = 4
innodb_thread_concurrency = 8
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 4M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = 0

[mysqldump]
quick
max_allowed_packet = 2M

[mysqld_safe]
log-error = /data/3507/mysql_lee3507.err
pid-file = /data/3507/mysqld.pid

(2) Edit the startup file vim mysqld

#!/bin/sh
##################################
#This scripts is created by Lee at 2017-12-10
#for mysql-multi
##################################

#init
port=3507                         # Note the distinction from 3506 instances
mysql_user="root"
mysql_pwd="admin"
CmdPath="/usr/local/mysql/bin"
mysql_sock="/data/${port}/mysql.sock"

#startup function
function_start(){
  if [ ! -e "$mysql_sock" ];then
    printf "Starting Mysql ...\n"
    /bin/sh ${CmdPath}/mysqld_safe --defaults-file=/data/${port}/my.cnf 2>&1 > /dev/null &
  else
    printf "Mysql is running ...\n"
    exit
  fi
}

#stop functino
function_stop(){
  if [ ! -e "$mysql_sock" ];then
    printf "Mysql is stopped...\n"
    exit
  else
    printf "Stoping Mysql...\n"
    ${CmdPath}/mysqladmin -u ${msyql_user} -p${msyql_pwd} -S /data/${port}/mysql.sock shutdown
  fi
}

#retart function
function_retart(){
   printf "Restarting Mysql...\n"
   function_stop
   sleep 2
   function_start
}

case $1 in
start)
   function_start
;;
stop)
   function_stop
;;
restart)
   function_restart
;;
*)
  printf "Usage: /data/${port}/mysqld {start|stop|restart}\n"
esac

(3) Assign configuration files to instances

cp /data/my.cnf mysqld /data/3506/
cp /data/my.cnf mysqld /data/3507/
sed -i 's#3507#3506#g' /data/3506/my.cnf /data/3506/mysqld

4. Permission Settings

find /data -name mysqld |xargs chmod 744                        # Add Executable Permissions to Startup File
chown -R mysql:mysql /data                          # Give mysql users permission to manage the data directory
chown -R mysql:mysql /usr/local/mysql     

5. Instance Initialization

cd /usr/local/mysql/scripts/
./mysql_install_db --basedir=/usr/local/mysql/ --datadir=/data/3506/data --user=mysql
./mysql_install_db --basedir=/usr/local/mysql/ --datadir=/data/3507/data --user=mysql

6. Set up environment variables (used here to add to the default directory of environment variables)

 cp /usr/local/mysql/bin/* /usr/local/sbin/ 

7. Specification startup file

ln -s /data/3506/mysqld /etc/init.d/mysqld3506
ln -s /data/3507/mysqld /etc/init.d/mysqld3507

4. MySQL Test Use

1. Start the service

 /etc/init.d/mysqld3306 start
 /etc/init.d/mysqld3307 start
 perhaps
 /data/3506/mysqld start
 /data/3507/mysqld start

1. Check if the port is started

netstat -tunlp |grep 350
tcp        0      0 0.0.0.0:3506                0.0.0.0:*                   LISTEN      18545/mysqld        
tcp        0      0 0.0.0.0:3507                0.0.0.0:*                   LISTEN      19902/mysqld

3. Log on to mysql (multiple instance mysql startup uses -S to specify socket)

mysql -S /data/3507/mysql.sock                 # Default passwordless login (before password is set)
mysql -uroot -p -S /data/3507/mysql.sock    

Special thanks: Teacher Oldboy's guidance!

Posted by m4rw3r on Sun, 21 Jun 2020 09:59:11 -0700