CentOS6.5安裝MariaDB10.0.15編譯安裝和多執行個體管理配置

來源:互聯網
上載者:User

CentOS6.5安裝MariaDB10.0.15編譯安裝和多執行個體管理配置

CentOS6.5 x86_64 系統

[root@e3 ~]# wget https://downloads.mariadb.org/interstitial/mariadb-10.0.15/source/mariadb-10.0.15.tar.gz/from/http%3A//mirrors.neusoft.edu.cn/mariadb
groupadd -r mysql
useradd -r -g mysql -s /sbin/nologin mysql
mkdir /data/mydata{1..3}
chown -R mysql:mysql  /data/*

安裝
 
yum -y install gcc gcc-c++ make cmake ncurses ncurses libxml2 libxml2-devel openssl-devel bison bison-devel #相依元件
解壓MariaDB源碼包
tar xf mariadb
cd mariadb-10.0.15/
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mydata  -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STPRAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWIYH_READLINE=1 -DWIYH_SSL=system -DVITH_ZLIB=system -DWITH_LOBWRAP=0 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock
-DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
make -j 4  -j 4 表示4核處理 能快點編譯
make install

輸出環境變數

[root@e3 ~]# vim /etc/profile.d/mysql.sh
export PATH=$PATH:/usr/local/mysql/bin/
[root@e3 mariadb-10.0.15]# . /etc/profile.d/mysql.sh

輸出標頭檔庫檔案man協助文檔
 
 vim /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
[root@e3 mariadb-10.0.15]# vim /etc/man.config
MANPATH /usr/local/mysql/man
[root@e3 mariadb-10.0.15]# man -M  /usr/local/mysql/man/ mysqld
[root@e3 tmp]# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/data/mydata1 --user=mysql

提供設定檔和啟動指令碼

[root@e3 mariadb-10.0.15]# cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf
[root@e3 mariadb-10.0.15]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@e3 mariadb-10.0.15]# chmod +x /etc/init.d/mysqld ^C
[root@e3 mariadb-10.0.15]# chkconfig mysqld on^C
[root@e3 mariadb-10.0.15]# /etc/init.d/mysqld start
然後測試
直接輸入mysql

多執行個體配置運行於不同的連接埠3306,3307,3308

設定檔如/etc/my.cnf
 
[client]
#password      = your_password
#port          = 3306
#socket        = /tmp/mysql.sock
default-character-set = utf8
 
# Here follows entries for some specific programs
[mysqld_multi]
mysqld    = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
user      = root
log = /var/log/mysql/mysqld.multi.log
#password      =      #如果你的mysql執行個體有密碼這一項就要啟動,並且寫上密碼,不然管理指令碼可以啟動,不能停止
 
[mysqld1]
port=3306
socket=/tmp/mysql3306.sock
pid-file=/tmp/mysql3306.pid
max_allowed_packet=1M
net_buffer_length=2k
table_open_cache=4
sort_buffer_size=64k
thread_stack=128k
basedir=/usr/local/mysql
datadir=/data/mydata1
server-id=1
 
[mysqld2]
port=3307
socket=/tmp/mysql3307.sock
pid-file=/tmp/mysql3307.pid
max_allowed_packet=1M
net_buffer_length=2k
table_open_cache=4
sort_buffer_size=64k
thread_stack=128k
basedir=/usr/local/mysql
datadir=/data/mydata2
server-id=1
 
[mysqld3]
port=3308
socket=/tmp/mysql3308.sock
pid-file=/tmp/mysql3308.pid
max_allowed_packet=1M
net_buffer_length=2k
table_open_cache=4
sort_buffer_size=64k
thread_stack=128k
basedir=/usr/local/mysql
datadir=/data/mydata3
server-id=1
#
# The MariaDB server

多執行個體管理指令碼
 
[root@e3 mariadb-10.0.15]# cp /usr/local/mysql/support-files/mysqld_multi.server /etc/init.d/mysqld.multi
[root@e3 mariadb-10.0.15]# chmod +x /etc/init.d/mysqld.multi

修改多執行個體指令碼來同時啟動,關閉3個執行個體

[root@e3 mariadb-10.0.15]# vim /etc/init.d/mysqld.multi

編輯修改

#!/bin/sh
#
# A simple startup script for mysqld_multi by Tim Smith and Jani Tolonen.
# This script assumes that my.cnf file exists either in /etc/my.cnf or
# /root/.my.cnf and has groups [mysqld_multi] and [mysqldN]. See the
# mysqld_multi documentation for detailed instructions.
#
# This script can be used as /etc/init.d/mysql.server
#
# Comments to support chkconfig on RedHat Linux
# chkconfig: 2345 64 36
# description: A very fast and reliable SQL database engine.
#
# Version 1.0
#
 
basedir=/usr/local/mysql
bindir=/usr/local/mysql/bin
conf=/etc/my.cnf
export PATH=$PATH:$bindir
 
if test -x $bindir/mysqld_multi
then
  mysqld_multi="$bindir/mysqld_multi";
else
  echo "Can't execute $bindir/mysqld_multi from dir $basedir";
  exit;
fi
 
case "$1" in
    'start' )
        "$mysqld_multi" --defaults-extra-file=$conf start $2
        ;;
    'stop' )
        "$mysqld_multi" --defaults-extra-file=$conf stop $2
        ;;
    'report' )
        "$mysqld_multi"  --defaults-extra-file=$conf report $2
        ;;
    'restart' )
        "$mysqld_multi" --defaults-extra-file=$conf stop $2
        "$mysqld_multi" --defaults-extra-file=$conf start $2
        ;;
    *)
        echo "Usage: $0 {start|stop|report|restart}" >&2
        ;;
esac

來測試!

[root@e3 mariadb-10.0.15]# /etc/init.d/mysqld.multi start 1,2,3
[root@e3 mariadb-10.0.15]# netstat -antlp |grep mysqld
tcp        0      0 :::3307                    :::*                        LISTEN      20628/mysqld       
tcp        0      0 :::3308                    :::*                        LISTEN      20630/mysqld       
tcp        0      0 :::3306                    :::*                        LISTEN      20619/mysqld       
[root@e3 mariadb-10.0.15]# /etc/init.d/mysqld.multi stop 1,2,3
[root@e3 mariadb-10.0.15]# netstat -antlp |grep mysqld

如何串連資料庫

[root@e3 tmp]# mysql -S /tmp/mysql3307.sock    這樣可以串連
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 10.0.15-MariaDB Source distribution
 
Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
MariaDB [(none)]>
 
[root@e3 tmp]# mysql -uroot -h127.0.0.1 -P3306 -p  這樣也可以串連
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.0.15-MariaDB Source distribution
 
Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
MariaDB [(none)]>

以此類推。

在 CentOS/RHEL/Scientific Linux 6 下安裝 LAMP (Apache with MariaDB and PHP)

MariaDB Proxy讀寫分離的實現

Linux下編譯安裝配置MariaDB資料庫的方法

CentOS系統使用yum安裝MariaDB資料庫

安裝MariaDB與MySQL並存

Ubuntu 上如何將 MySQL 5.5 資料庫遷移到 MariaDB 10 

[翻譯]Ubuntu 14.04 (Trusty) Server 安裝 MariaDB 

相關文章

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.