centos7环境下创建mysql5.6多实例的方法详解
本文实例讲述了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"mysqlstart...\n" /bin/sh${cmd_path}/mysqld_safe--defaults-file=/mysql-instance/${port}/my.cnf2>&1>/dev/null& else printf"mysqlisrunning...\n" exit fi } mysql_stop(){ if[!-e"$mysql_sock"];then printf"mysqlisstopped...\n" exit else printf"mysqlstop...\n" ${cmd_path}/mysqladmin-u${mysql_user}-p${mysql_pwd}-S/mysql-instance/${port}/mysql.sockshutdown fi } mysql_restart(){ printf"mysqlrestart...\n" mysql_stop sleep2 mysql_start } case$1in start)mysql_start;; stop)mysql_stop;; restart)mysql_restart;; *) printf"usage:/data/${port}/mysql{start|stop|restart}\n" esac
六、授权mysql用户目录权限
>chown-Rmysql.mysql/mysql-instance >chmod700/mysql-instance/3308/mysql >chmod700/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/mysqlstart >/mysql-instance/3309/mysqlstart >netstat-lntup|grep330
九、登陆mysql实例
>mysql-uroot-p-S/mysql-instance/3308/mysql.sock
更多关于MySQL相关内容感兴趣的读者可查看本站专题:《MySQL查询技巧大全》、《MySQL常用函数大汇总》、《MySQL日志操作技巧大全》、《MySQL事务操作技巧汇总》、《MySQL存储过程技巧大全》及《MySQL数据库锁相关技巧汇总》
希望本文所述对大家MySQL数据库计有所帮助。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。