zoukankan      html  css  js  c++  java
  • MySQL5.6多实例安装

    MySQL-5.6.36.tar.gz多实例安装

    查看官方安装说明

    more INSTALL-SOURCE

    安装cmake及相关依赖包

    yum install -y cmake gcc

    [root@vhost1 ~]# cat /etc/redhat-release
    Red Hat Enterprise Linux Server release 7.0 (Maipo)

    [root@vhost1 ~]# ls
    cmake-2.8.8.tar.gz  mysql-5.6.36.tar.gz
    [root@vhost1 ~]# tar xf cmake-2.8.8.tar.gz
    [root@vhost1 ~]# cd cmake-2.8.8
    #cmake has bootstrapped.
    [root@vhost1 cmake-2.8.8]# ./configure
    [root@vhost1 cmake-2.8.8]# gmake
    [root@vhost1 cmake-2.8.8]# gmake install

    [root@vhost1 ~]# yum install ncurses-devel -y   #使应用程序直接控制终端屏幕显示的库

    创建用户和组

    [root@vhost1 ~]#groupadd -g 200 mysql

    [root@vhost1 ~]#useradd mysql -u 200 -s /sbin/nologin -M -g mysql

    创建安装MySQL软件目录

    [root@vhost1 ~]#mkdir -p /application/mysql-5.6.36

    解压编译MySQL

    [root@vhost1 ~]#cd mysql-5.6.36

    [root@vhost1 mysql-5.6.36]# 

    cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.6.36
    -DMYSQL_DATADIR=/application/mysql-5.6.36/data
    -DMYSQL_UNIX_ADDR=/application/mysql-5.6.36/tmp/mysql.sock
    -DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii
    -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
    -DENABLED_LOCAL_INFILE=1
    -DWITH_READLINE=1
    -DWITH_EMBEDDED_SERVER=1
    -DWITH_DEBUG=0
    -DWITHOUT_PARTITION_STORAGE_ENGINE=0

    [root@vhost1 mysql-5.6.36]# make && make install 

    [root@vhost1 ~]#ln -s /application/mysql-5.6.36/ /application/mysql

    #修改安装目录权限为mysql

    [root@vhost1 ~]#cd /application

    [root@vhost1 ~]#chown -R mysql .

    [root@vhost1 ~]#chgrp -R mysql .

     创建实例目录:

    [root@vhost1 ~]#mkdir -p /mysqldata/3306/data

    [root@vhost1 ~]#mkdir -p /mysqldata/3307/data

    拷贝配置文件模板和启动脚本模板

    [root@vhost1 mysql]# cp support-files/my-default.cnf /mysqldata/3306/my.cnf 

    [root@vhost1 mysql]# cp support-files/mysql.server /mysqldata/3306/mysql

    修改权限

    [root@vhost1 ~]#chown -R mysql.mysql /mysqldata/3306

    [root@vhost1 ~]#chmod -R 755  /mysqldata/3306

    修改配置文件

     [root@vhost1 ~]#vi /mysqldata/3306/my.cnf 

    [mysqld]
    user = mysql
    basedir = /application/mysql
    datadir = /mysqldata/3306/data
    port = 3306
    server_id = 1
    socket = /mysqldata/3306/data/mysql3306.sock
    log-error = /mysqldata/3306/mysql3306_error.log
    pid-file = /mysqldata/3306/mysql3306.pid
    my.cnf

    #初始化数据库实例

    scripts/mysql_install_db --defaults-file=/mysqldata/3306/my.cnf 

    #启动数据库

    bin/mysqld_safe --defaults-file=/mysqldata/3306/my.cnf & 

    #查看进程

    ps aux |grep mysql

    #命令行通过socket进入数据库

    [root@vhost1 ~]#mysql -uroot -p  -S /mysqldata/3306/mysql3306.sock

    #修改脚本(官方给的太复杂,问题也多,下面是简化官方后的脚本)

    [root@vhost1 ~]#vi /mysqldata/3306/mysql

    #!/bin/sh
    
    basedir=/application/mysql
    datadir=/mysqldata/3306/data
    
    bindir=$basedir/bin
    service_startup_timeout=900
    lsb_functions="/lib/lsb/init-functions"
    if test -f $lsb_functions ; then
      . $lsb_functions
    else
      log_success_msg()
      {
        echo " SUCCESS! $@"
      }
      log_failure_msg()
      {
        echo " ERROR! $@"
      }
    fi
    
    wait_for_pid () {
      verb="$1"           # created | removed
      pid="$2"            # process ID of the program operating on the pid-file
      pid_file_path="$3" # path to the PID file.
    
      i=0
      avoid_race_condition="by checking again"
    
      while test $i -ne $service_startup_timeout ; do
    
        case "$verb" in
          'created')
            # wait for a PID-file to pop into existence.
            test -s "$pid_file_path" && i='' && break
            ;;
          'removed')
            # wait for this PID-file to disappear
            test ! -s "$pid_file_path" && i='' && break
            ;;
          *)
            echo "wait_for_pid () usage: wait_for_pid created|removed pid pid_file_path"
            exit 1
            ;;
        esac
    
        # if server isn't running, then pid-file will never be updated
        if test -n "$pid"; then
          if kill -0 "$pid" 2>/dev/null; then
            :  # the server still runs
          else
            # The server may have exited between the last pid-file check and now.  
            if test -n "$avoid_race_condition"; then
              avoid_race_condition=""
              continue  # Check again.
            fi
    
            # there's nothing that will affect the file.
            log_failure_msg "The server quit without updating PID file ($pid_file_path)."
            return 1  # not waiting any more.
          fi
        fi
    
        echo $echo_n ".$echo_c"
        i=`expr $i + 1`
        sleep 1
    
      done
    
      if test -z "$i" ; then
        log_success_msg
        return 0
      else
        log_failure_msg
        return 1
      fi
    }
    
    mysqld_pid_file_path=$datadir/../mysql3306.pid
    mode=$1    # start or stop
    case "$mode" in
      'start')
        # Start daemon
    
        # Safeguard (relative paths, core dumps..)
        cd $basedir
    
        echo $echo_n "Starting MySQL"
        if test -x $bindir/mysqld_safe
        then
          # Give extra arguments to mysqld with the my.cnf file. This script
          # may be overwritten at next upgrade.
          $bindir/mysqld_safe --defaults-file=$datadir/../my.cnf  >/dev/null 2>&1 &
          wait_for_pid created "$!" "$mysqld_pid_file_path"; return_value=$?
    
          # Make lock for RedHat / SuSE
          if test -w "$lockdir"
          then
            touch "$lock_file_path"
          fi
    
          exit $return_value
        else
          log_failure_msg "Couldn't find MySQL server ($bindir/mysqld_safe)"
        fi
        ;;
    
      'stop')
        # Stop daemon. We use a signal here to avoid having to know the
        # root password.
    
        if test -s "$mysqld_pid_file_path"
        then
          mysqld_pid=`cat "$mysqld_pid_file_path"`
    
          if (kill -0 $mysqld_pid 2>/dev/null)
          then
            echo $echo_n "Shutting down MySQL"
            kill $mysqld_pid
            # mysqld should remove the pid file when it exits, so wait for it.
            wait_for_pid removed "$mysqld_pid" "$mysqld_pid_file_path"; return_value=$?
          else
            log_failure_msg "MySQL server process #$mysqld_pid is not running!"
            rm "$mysqld_pid_file_path"
          fi
    
          # Delete lock for RedHat / SuSE
          if test -f "$lock_file_path"
          then
            rm -f "$lock_file_path"
          fi
          exit $return_value
        else
          log_failure_msg "MySQL server PID file could not be found!"
        fi
        ;;
    
      'restart')
        # Stop the service and regardless of whether it was
        # running or not, start it again.
        if $datadir/../mysql stop  $other_args; then
          $datadir/../mysql start $other_args
        else
          log_failure_msg "Failed to stop running server, so refusing to try to start."
          exit 1
        fi
        ;;
    
      'reload'|'force-reload')
        if test -s "$mysqld_pid_file_path" ; then
          read mysqld_pid <  "$mysqld_pid_file_path"
          kill -HUP $mysqld_pid && log_success_msg "Reloading service MySQL"
          touch "$mysqld_pid_file_path"
        else
          log_failure_msg "MySQL PID file could not be found!"
          exit 1
        fi
        ;;
      'status')
        # First, check to see if pid file exists
        if test -s "$mysqld_pid_file_path" ; then
          read mysqld_pid < "$mysqld_pid_file_path"
          if kill -0 $mysqld_pid 2>/dev/null ; then
            log_success_msg "MySQL running ($mysqld_pid)"
            exit 0
          else
            log_failure_msg "MySQL is not running, but PID file exists"
            exit 1
          fi
        else
          # Try to find appropriate mysqld process
          mysqld_pid=`pidof $libexecdir/mysqld`
    
          # test if multiple pids exist
          pid_count=`echo $mysqld_pid | wc -w`
          if test $pid_count -gt 1 ; then
            log_failure_msg "Multiple MySQL running but PID file could not be found ($mysqld_pid)"
            exit 5
          elif test -z $mysqld_pid ; then
            if test -f "$lock_file_path" ; then
              log_failure_msg "MySQL is not running, but lock file ($lock_file_path) exists"
              exit 2
            fi
            log_failure_msg "MySQL is not running"
            exit 3
          else
            log_failure_msg "MySQL is running but PID file could not be found"
            exit 4
          fi
        fi
        ;;
        *)
          # usage
          echo "Usage: $datadir/../mysql  {start|stop|restart|reload|force-reload|status}"
          exit 1
        ;;
    esac
    
    exit 0
    mysql启动脚本

    #脚本使用方法

    [root@vhost1 ~]#chmod u+x /mysqldata/3306/mysql 

    [root@vhost1 ~]#/mysqldata/3306/mysql   stop

  • 相关阅读:
    讲讲HashCode的作用
    自定义一个类加载器
    从为什么String=String谈到StringBuilder和StringBuffer
    System.load(String filename)和System.loadLibrary(String libname)的区别
    自己实现一个Native方法的调用
    Java对象表示方式1:序列化、反序列化和transient关键字的作用
    Java对象表示方式2:XStream实现对对象的XML化
    static关键字作用
    final的作用
    多态
  • 原文地址:https://www.cnblogs.com/elontian/p/7490672.html
Copyright © 2011-2022 走看看