码迷,mamicode.com
首页 > 数据库 > 详细

CentOS6.5安装MariaDB10.0.15编译安装和多实例管理配置

时间:2014-12-30 20:52:14      阅读:320      评论:0      收藏:0      [点我收藏+]

标签:

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       =

[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)]>
以此类推。













































CentOS6.5安装MariaDB10.0.15编译安装和多实例管理配置

标签:

原文地址:http://my.oschina.net/kcw/blog/362430

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!