您好,登錄后才能下訂單哦!
本文實例講述了centos7環境下創建mysql5.6多實例的方法。分享給大家供大家參考,具體如下:
一、mysql安裝目錄說明
mysql5.6以二進制安裝包安裝在/data/mysql56下
數據目錄為/data/mysql56/data下
配置文件為/etc/my.cnf下
二、多實例目錄說明
/mysql-instance
|-- 3308
|-- data #3308實例數據目錄
|-- 3309
|-- data #3309實例數據目錄
> mkdir -p /mysql-instance/3308/data > mkdir -p /mysql-instance/3309/data
三、復制配置文件到實例目錄下
> 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
五、創建mysql多實例啟動文件
> vi /mysql-instance/3308/mysql > vi /mysql-instance/3309/mysql
#!/bin/sh port=3308 mysql_user="root" #請填寫自已數據庫密碼 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
六、授權mysql用戶目錄權限
> chown -R mysql.mysql /mysql-instance > chmod 700 /mysql-instance/3308/mysql > chmod 700 /mysql-instance/3309/mysql
七、初始化mysql多實例數據庫文件
> 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多實例
> /mysql-instance/3308/mysql start > /mysql-instance/3309/mysql start > netstat -lntup|grep 330
九、登陸mysql實例
> mysql -uroot -p -S /mysql-instance/3308/mysql.sock
更多關于MySQL相關內容感興趣的讀者可查看本站專題:《MySQL查詢技巧大全》、《MySQL常用函數大匯總》、《MySQL日志操作技巧大全》、《MySQL事務操作技巧匯總》、《MySQL存儲過程技巧大全》及《MySQL數據庫鎖相關技巧匯總》
希望本文所述對大家MySQL數據庫計有所幫助。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。