前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >mysql启动多个实例

mysql启动多个实例

作者头像
dogfei
发布2020-07-31 11:57:16
3.3K0
发布2020-07-31 11:57:16
举报
文章被收录于专栏:devops探索devops探索devops探索

环境

机器环境:CentOS Linux release 7.4.1708 (Core)

MySQL版本:mysql Ver 14.14 Distrib 5.6.35, for Linux (x86_64) using EditLine wrapper

配置

MySQL是已经装好的了,后来由于业务需求,需要再起另一个端口,和之前的默认库分离开来,单独使用,所以使用了多实例。

1、创建每个实例的目录

1 2

mkdir /data/{3306,3307}/data chown -R mysql.mysql /data/{3306,3307}/data

2、准备配置文件

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50

#3306 [mysqld] sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES port = 3306 socket = /data/3306/mysql.sock basedir =/usr/local/mysql datadir = /data/3306/data user = mysql pid-file=/data/3306/mysqld.pid character-set-server=utf8 expire_logs_days = 3 skip-external-locking key_buffer_size = 64M max_allowed_packet = 100M table_open_cache = 256 myisam_sort_buffer_size = 16M query_cache_type = 1 log-bin=mysql-bin table_open_cache = 512 innodb_flush_log_at_trx_commit=1 innodb_log_buffer_size=4M innodb_buffer_pool_size = 128M key_buffer_size=32M tmp_table_size=32M max_heap_table_size=64M read_buffer_size=4M read_rnd_buffer_size=8M sort_buffer_size=8M max_connections=1024 thread_cache_size=60 query_cache_size=64M wait_timeout=20 [mysql] socket = /data/3306/mysql.sock pid-file=/data/3306/mysqld.pid [mysqldump] socket = /data/3306/mysql.sock pid-file=/data/3306/mysqld.pid quick max_allowed_packet = 100M pid-file=/data/3306/mysqld.pid [mysqladmin] pid-file=/data/3306/mysqld.pid socket = /data/3306/mysql.sock [client] pid-file=/data/3306/mysqld.pid socket = /data/3306/mysql.sock [mysqld_safe] log-error=/data/3306/mysql_3306.err pid-file=/data/3306/mysqld.pid

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

[mysqld] sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES port = 3307 socket = /data/3307/mysql.sock basedir =/usr/local/mysql datadir = /data/3307/data user = mysql pid-file=/data/3307/mysqld.pid character-set-server=utf8 expire_logs_days = 3 skip-external-locking key_buffer_size = 64M max_allowed_packet = 100M table_open_cache = 256 myisam_sort_buffer_size = 16M query_cache_type = 1 log-bin=mysql-bin table_open_cache = 512 innodb_flush_log_at_trx_commit=1 innodb_log_buffer_size=4M innodb_buffer_pool_size = 128M key_buffer_size=32M tmp_table_size=32M max_heap_table_size=64M read_buffer_size=4M read_rnd_buffer_size=8M sort_buffer_size=8M max_connections=1024 thread_cache_size=60 query_cache_size=64M wait_timeout=20 [mysql] socket = /data/3307/mysql.sock pid-file=/data/3307/mysqld.pid [mysqldump] socket = /data/3307/mysql.sock pid-file=/data/3307/mysqld.pid quick max_allowed_packet = 100M pid-file=/data/3307/mysqld.pid [mysqladmin] pid-file=/data/3307/mysqld.pid socket = /data/3307/mysql.sock [client] pid-file=/data/3307/mysqld.pid socket = /data/3307/mysql.sock [mysqld_safe] log-error=/data/3307/mysql_3307.err pid-file=/data/3307/mysqld.pid

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55

#3307启动脚本 #!/bin/sh #init port=3307 mysql_user="root" mysql_pwd="clickwise10050" CmdPath="/usr/local/mysql/bin" mysql_sock="/data/${port}/mysql.sock" #startup function function_start_mysql() { if [ ! -e "$mysql_sock" ];then printf "Starting MySQL...\n" /bin/sh ${CmdPath}/mysqld_safe --defaults-file=/data/${port}/my.cnf 2>&1 > /dev/null & else printf "MySQL is running...\n" exit fi } #stop function function_stop_mysql() { if [ ! -e "$mysql_sock" ];then printf "MySQL is stopped...\n" exit else printf "Stoping MySQL...\n" ${CmdPath}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql.sock shutdown fi } #restart function function_restart_mysql() { printf "Restarting MySQL...\n" function_stop_mysql sleep 2 function_start_mysql } case $1 in start) function_start_mysql ;; stop) function_stop_mysql ;; restart) function_restart_mysql ;; *) printf "Usage: /data/${port}/mysql {start|stop|restart}\n" esac

3306的启动脚本只需改下端口即可

3、初始化数据目录

1 2 3 4 5 6 7

1、进入到MySQL的安装目录 cd /usr/local/mysql 2、执行初始化 cd scripts ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/3306/data ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/3307/data

4、启动

1 2

/data/3306/mysql start /data/3307/mysql start

问题

在启动过程中,我遇到了启动不起来的情况,通过查看错误信息,发现mysql没有权限对每个目录进行写,所以修改权限

报错信息:

1 2 3

2018-04-13 14:46:32 31349 [ERROR] Can't start server : Bind on unix socket: Permission denied 2018-04-13 14:46:32 31349 [ERROR] Do you already have another mysqld server running on socket: /data/3306/mysql.sock ? 2018-04-13 14:46:32 31349 [ERROR] Aborting

1

chmyl -R 755 /data/{3306,3307}/*

如果需要再加一个实例,只需重复上述步骤即可。这种场景只能用于并发不高的情况下。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-04-13,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 环境
  • 配置
  • 问题
相关产品与服务
云数据库 SQL Server
腾讯云数据库 SQL Server (TencentDB for SQL Server)是业界最常用的商用数据库之一,对基于 Windows 架构的应用程序具有完美的支持。TencentDB for SQL Server 拥有微软正版授权,可持续为用户提供最新的功能,避免未授权使用软件的风险。具有即开即用、稳定可靠、安全运行、弹性扩缩等特点。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档