本文實(shí)例講述了centos7環(huán)境下創(chuàng)建MySQL5.6多實(shí)例的方法。分享給大家供大家參考,具體如下:
創(chuàng)新互聯(lián)堅(jiān)信:善待客戶,將會成為終身客戶。我們能堅(jiān)持多年,是因?yàn)槲覀円恢笨芍档眯刨嚒N覀儚牟缓鲇瞥踉L客戶,我們用心做好本職工作,不忘初心,方得始終。十載網(wǎng)站建設(shè)經(jīng)驗(yàn)創(chuàng)新互聯(lián)是成都老牌網(wǎng)站營銷服務(wù)商,為您提供成都網(wǎng)站建設(shè)、網(wǎng)站制作、網(wǎng)站設(shè)計(jì)、H5頁面制作、網(wǎng)站制作、品牌網(wǎng)站建設(shè)、微信小程序服務(wù),給眾多知名企業(yè)提供過好品質(zhì)的建站服務(wù)。
一、mysql安裝目錄說明
mysql5.6以二進(jìn)制安裝包安裝在/data/mysql56下
數(shù)據(jù)目錄為/data/mysql56/data下
配置文件為/etc/my.cnf下
二、多實(shí)例目錄說明
/mysql-instance
|-- 3308
|-- data #3308實(shí)例數(shù)據(jù)目錄
|-- 3309
|-- data #3309實(shí)例數(shù)據(jù)目錄
> mkdir -p /mysql-instance/3308/data > mkdir -p /mysql-instance/3309/data
三、復(fù)制配置文件到實(shí)例目錄下
> cp /data/mysql56/support-files/my-default.cnf /mysql-instance/3308/my.cnf > cp /data/mysql56/support-files/my-default.cnf /mysql-instance/3309/my.cnf
四、修改配置文件
> vi /mysql-instance/3308/my.cnf > vi /mysql-instance/3309/my.cnf
[client] port = 3308 socket = /mysql-instance/3308/mysql.sock [mysql] no-auto-rehash [mysqld] user = mysql port = 3308 socket = /mysql-instance/3308/mysql.sock basedir = /data/mysql56 datadir = /mysql-instance/3308/data pid-file = /mysql-instance/3308/mysql.pid relay-log = /mysql-instance/3308/relay-bin relay-log-info-file = /mysql-instance/3308/relay-log.info server-id = 12 [mysqld_safe] log-error = /mysql-instance/3308/mysql.err pid-file = /mysql-instance/3308/mysql.pid
3309的配置同上,只需把3308的地方換成3309
五、創(chuàng)建mysql多實(shí)例啟動文件
> vi /mysql-instance/3308/mysql > vi /mysql-instance/3309/mysql
#!/bin/sh port=3308 mysql_user="root" #請?zhí)顚懽砸褦?shù)據(jù)庫密碼 mysql_pwd="123456" cmd_path="/data/mysql56/bin" mysql_sock="/mysql-instance/${port}/mysql.sock" mysql_start() { if [ ! -e "$mysql_sock" ];then printf "mysql start ... \n" /bin/sh ${cmd_path}/mysqld_safe --defaults-file=/mysql-instance/${port}/my.cnf 2>&1 > /dev/null & else printf "mysql is running ... \n" exit fi } mysql_stop() { if [ ! -e "$mysql_sock" ];then printf "mysql is stopped ... \n" exit else printf "mysql stop ... \n" ${cmd_path}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S /mysql-instance/${port}/mysql.sock shutdown fi } mysql_restart() { printf "mysql restart ... \n" mysql_stop sleep 2 mysql_start } case $1 in start) mysql_start ;; stop) mysql_stop ;; restart) mysql_restart ;; *) printf "usage: /data/${port}/mysql {start|stop|restart}\n" esac
六、授權(quán)mysql用戶目錄權(quán)限
> chown -R mysql.mysql /mysql-instance > chmod 700 /mysql-instance/3308/mysql > chmod 700 /mysql-instance/3309/mysql
七、初始化mysql多實(shí)例數(shù)據(jù)庫文件
> cd /daa/mysql56/scripts > ./mysql_install_db --basedir=/data/mysql56 --datadir=/mysql-instance/3308/data --user=mysql > ./mysql_install_db --basedir=/data/mysql56 --datadir=/mysql-instance/3309/data --user=mysql
八、啟動mysql多實(shí)例
> /mysql-instance/3308/mysql start > /mysql-instance/3309/mysql start > netstat -lntup|grep 330
九、登陸mysql實(shí)例
> mysql -uroot -p -S /mysql-instance/3308/mysql.sock
更多關(guān)于MySQL相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《MySQL查詢技巧大全》、《MySQL常用函數(shù)大匯總》、《MySQL日志操作技巧大全》、《MySQL事務(wù)操作技巧匯總》、《MySQL存儲過程技巧大全》及《MySQL數(shù)據(jù)庫鎖相關(guān)技巧匯總》
希望本文所述對大家MySQL數(shù)據(jù)庫計(jì)有所幫助。