mariadb10.2 Multi-instance

Source: Internet
Author: User

    1. Download mariadb with MARIADB official source.

[Email protected] ~]# Vim/etc/yum.repos.d/mariadb.repo [mariadb] name = mariadb BaseURL = HTTP://YUM.M ARIADB.ORG/10.2/CENTOS7-AMD64 gpgkey=https://yum.mariadb.org/rpm-gpg-key-mariadb gpgcheck=1

However, download the mariadb with Yum:

Yum Install Mariadb-server mariadb-client-y

2. Create the data directory you want to use. I created two on this side, one for 3306 ports and one for 3307.

MKDIR/DATA/NEWOA/DATA-PV mkdir/data/travel/data/-PV chown-r mysql:mysql/data/

3. Initialize two databases:

Mysqld--initialize-insecure--datadir=/data/newoa/data--user=mysql mysqld--initialize-insecure--datadir=/data/tr avel/data/--user=mysql

4. Start after initialization, connect to database after successful startup and modify [email protected] User's password, then exit.

ALTER USER ' root ' @ ' localhost ' identified by ' 123456 ';

5. Modify the two configuration files, the processing of NEWOA and the travel directory are created by themselves:

[Email protected] ~]# VIM/ETC/MY.CNF.D/NEWOA/MY.CNF [mysqld]port=3306datadir=/data/newoa/datasocket=/data/newoa/ Data/mysql.sockserver_id=201log-bin=mysql-binbinlog_format=mixedrelay-log = Relay-binuser=mysql[mysqld_safe] Log-error=/data/newoa/data/mysqld.logpid-file=/data/newoa/data/mysqld.pid[[email protected] ~]# vim/etc/my.cnf.d/ TRAVEL/MY.CNF [Mysqld]port=3307datadir=/data/travel/datasocket=/data/travel/data/mysql.sockserver_id=207log-bin =mysql-binbinlog_format=mixedrelay-log = relay-binuser=mysql[mysqld_safe]log-error=/data/travel/data/ Mysqld.logpid-file=/data/travel/data/mysqld.pid

6. Create a startup script.

    The following is the management script/etc/init.d/mysqld3306 for 3306 instances, modified from the original administrative script/etc/init.d/mysqld. Since I am a yum installer, MySQL basedir is/usr, and if it is a compiled installation or a generic binary installation, modify the Basedir variable in the script below. Copy this management script as/etc/init.d/mysqld3307 and modify the next port=3307 to serve as a service management script for 3307 instances. $datadir as well as the CNF path to make modifications.

[[email protected] ~]# vim /etc/init.d/mysqld3306#!/bin/sh## mysqld     This shell script takes care of starting and stopping#         the MySQL subsystem  (mysqld) .## chkconfig:  345 64 36# description:    mysql database server.#  Processname: mysqld# source function library.  /etc/rc.d/init.d/functions# source networking configuration.  /etc/sysconfig/networkbasedir=/usrexec= "$basedir/bin/mysqld_safe" prog= "mysqld" port=3306datadir= "/data/ Newoa/data "socketfile=" $datadir/mysql.sock "errlogfile=" $datadir/mysqld.log "mypidfile=" $datadir/mysqld.pid "cnf= "/etc/my.cnf.d/newoa/my.cnf" # set timeouts here so they can be  Overridden from /etc/sysconfig/mysqldstarttimeout=120stoptimeout=60# set in /etc/sysconfig/mysqld, will be passed to mysqld_safemysqld_opts=[ -e /etc/ sysconfig/$prog  ] && . /etc/sysconfig/$proglockfile =/var/lock/subsys/$progcase   $socketfile  in    /*)  adminsocket= "$socketfile"  ;;      *)  adminsocket= "$datadir/$socketfile"  ;; Esacstart () {    [ -x  $exec  ] | |  exit 5    # check to see if it ' s already  running    response=$ (/usr/bin/mysqladmin --no-defaults --socket= "$adminsocket"  --USER=UNKNOWN_MYSQL_USER PING 2>&1)     if [ $? =  0 ]; then    # already running, do nothing     action $ "starting  $prog: "  /bin/true    ret=0  & NBsp; elif echo  "$RESPONSE"  | grep -q  "Access denied for user"     then    # already running, do nothing     action $ "starting  $prog: "  /bin/true    ret=0     else    # Now start service     $exec   $MYSQLD _opts --defaults-file= "$cnf"  --datadir= "$datadir"  --socket= "$socketfile"           --pid-file= "$mypidfile"           --basedir= "$basedir"  --user=mysql >/dev/null &     safe_pid=$!    # spin for a maximum of n seconds  Waiting for the server to come up;    # exit the  loop immediately if mysqld_safe process disappears.    # rather than  assuming we know a valid username, accept an  "access     # denied " response as meaning the server is functioning.     ret=0    timeout= "$STARTTIMEOUT"     while [   $TIMEOUT  -gt 0 ]; do        response=$ (/usr/ bin/mysqladmin --no-defaults --socket= "$adminsocket"  --user=unknown_mysql_user ping 2 >&1)  && break        echo  "$RESPONSE"  | grep -q  "Access denied for user"  && break         if ! /bin/kill -0  $safe _pid 2>/dev/null;  then        echo  "Mysql daemon failed to start."         ret=1        break         fi        sleep 1         let timeout=${timeout}-1    done     if [  $TIMEOUT  -eq 0 ]; then         echo  "Timeout error occurred trying to start mysql  daemon. "         ret=1    fi    if  [  $ret  -eq 0 ]; then        action  $ "starting  $prog: "  /bin/true        touch $ Lockfile    else        action $ "starting  $prog: "  /bin/false     fi    fi    return  $ret}stop () {     if [ ! -f  "$mypidfile"  ]; then         # not running; per LSB standards this is  "OK"          action $ "stopping  $prog: "  /bin/true         return 0    fi    mysqlpid= ' Cat   "$mypidfile"     if [ -n  "$MYSQLPID"  ]; then         /bin/kill  "$MYSQLPID"  >/dev/null 2>&1         ret=$?        if [  $ret  -eq 0 ]; then        timeout= "$STOPTIMEOUT"          while [  $TIMEOUT  -gt 0 ]; do             /bin/kill -0  "$MYSQLPID"  >/dev/null 2> &1 | |  break            sleep 1             let TIMEOUT=${TIMEOUT}-1         done        if [  $TIMEOUT  -eq 0 ]; then            echo   "Timeout error occurred trying to stop mysql daemon."             ret=1             action $ "stopping  $prog: "  /bin/false         else            rm -f  $lockfile              rm -f  "$socketfile"              action $ "stopping  $prog: "  / Bin/true        fi        else         action $ "stopping  $prog: "  /bin/false         fi    else         # failed to read pidfile, probably insufficient  permissions        action $ "stopping  $prog: "  /bin /false        ret=4    fi    return  $ret}restart () {     stop    start}condrestart () {    [ -e $ lockfile ] && restart | |  :}# See how we were called.case  "$"  in  start)      start    ;;   stop)     stop    ;;   status)     status -p  "$mypidfile"   $prog      ;;   restart)     restart    ;;   condrestart|try-restart)     condrestart    ;;   reload)     exit 3    ;;   force-reload)     restart    ;;   *)     echo $ "usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload} "    exit  2esacexit $?

Use the following command to manage the instance:

Service mysqld3306 {start|stop|status|restart}service mysqld3307 {Start|stop|status|restart}

Above method Reference: https://www.centos.bz/2017/09/mysql%E3%80%81mariadb%E5%AE%89%E8%A3%85%E5%92%8C%E5%A4%9A%E5%AE%9E%E4%BE% 8b%e9%85%8d%e7%bd%ae/




This article is from the "linuxnew" blog, make sure to keep this source http://jimchen.blog.51cto.com/10026955/1969770

mariadb10.2 Multi-instance

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.