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/mariadbgroupadd -r mysqluseradd -r -g mysql -s /sbin/nologin mysqlmkdir /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_cimake -j 4 -j 4 表示4核处理 能快点编译make install
输出环境变量
[root@e3 ~]# vim /etc/profile.d/mysql.shexport 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.configMANPATH /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
初始化mysql多实例
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/data/mydata1 --user=mysql
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/data/mydata2 --user=mysql
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/data/mydata3 --user=mysql
配置文件如/etc/my.cnf
[client]#password = your_password#port = 3306#socket = /tmp/mysql.sockdefault-character-set = utf8# Here follows entries for some specific programs[mysqld_multi]mysqld = /usr/local/mysql/bin/mysqld_safemysqladmin = /usr/local/mysql/bin/mysqladminuser = rootlog = /var/log/mysql/mysqld.multi.log#password = #如果你的mysql实例有密码这一项就要启动,并且写上密码,不然管理脚本可以启动,不能停止[mysqld1]port=3306socket=/tmp/mysql3306.sockpid-file=/tmp/mysql3306.pidmax_allowed_packet=1Mnet_buffer_length=2ktable_open_cache=4sort_buffer_size=64kthread_stack=128kbasedir=/usr/local/mysqldatadir=/data/mydata1server-id=1[mysqld2]port=3307socket=/tmp/mysql3307.sockpid-file=/tmp/mysql3307.pidmax_allowed_packet=1Mnet_buffer_length=2ktable_open_cache=4sort_buffer_size=64kthread_stack=128kbasedir=/usr/local/mysqldatadir=/data/mydata2server-id=1[mysqld3]port=3308socket=/tmp/mysql3308.sockpid-file=/tmp/mysql3308.pidmax_allowed_packet=1Mnet_buffer_length=2ktable_open_cache=4sort_buffer_size=64kthread_stack=128kbasedir=/usr/local/mysqldatadir=/data/mydata3server-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/mysqlbindir=/usr/local/mysql/binconf=/etc/my.cnfexport PATH=$PATH:$bindirif test -x $bindir/mysqld_multithen mysqld_multi="$bindir/mysqld_multi";else echo "Can't execute $bindir/mysqld_multi from dir $basedir"; exit;ficase "$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 mysqldtcp 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 2Server version: 10.0.15-MariaDB Source distributionCopyright (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 3Server version: 10.0.15-MariaDB Source distributionCopyright (c) 2000, 2014, Oracle, SkySQL Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]>
以此类推。