[root@e3 ~]# wget %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 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, , 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并存
上如何将 MySQL 5.5 数据库迁移到 MariaDB 10
[翻译]Ubuntu 14.04 (Trusty) Server 安装 MariaDB
MariaDB 的详细介绍:
MariaDB 的下载地址:
本文永久更新链接地址: