linux系统centos 6.5,使用二进制安装多实例mysql 5.5.60

所需安装包mysql-5.5.60-linux-glibc2.12-x86_64.tar.gz、ncurses-devel-5.7-4.20090207.el6.x86_64.rpm、libaio-devel-0.3.107-10.el6.x86_64.rpm

在一台机器上开启多个不同的服务端口,运行多个mysql服务进程,这些mysql多实例共用一套mysql安装程序,使用不同(也可以相同)的my.cnf配置文件、启动程序、数据文件,多个实例根据配置文件对应的设定值来取得对应数量的服务器相关硬件资源。多实例类似合租的各个房间,硬件资源相当于公用的厨房、卫生间和客厅

创建更新包目录,并将三个安装包上传至该目录下,赋予执行权限

[root@oldboy ~]# mkdir -p /home/oldboy/tools
[root@oldboy ~]# cd /home/oldboy/tools
[root@oldboy tools]# chmod +x *
[root@oldboy tools]# rpm -ivh --nodeps ncurses-devel-5.7-4.20090207.el6.x86_64.rpm
[root@oldboy tools]# rpm -ivh libaio-devel-0.3.-.el6.x86_64.rpm

创建用户和组、解压二进制mysql安装包、并创建软连接

[root@oldboy tools]# groupadd mysql
[root@oldboy tools]# useradd -M mysql -g mysql -s /sbin/nologin
[root@oldboy tools]# tar zxf mysql-5.5.-linux-glibc2.-x86_64.tar.gz
[root@oldboy tools]# mkdir -p /application/
[root@oldboy tools]# mv mysql-5.5.-linux-glibc2.-x86_64 /application/mysql-5.5.
[root@oldboy tools]# ln -s /application/mysql-5.5./ /application/mysql

以/data目录作为mysql多实例的总根目录,在/data下创建mysql实例端口号3306、3307的二级目录,不同的端口号代表不同的实例,各个实例目录下又包含各自的数据文件、配置文件及启动文件。

[root@oldboy tools]# mount /dev/cdrom /mnt
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@oldboy tools]# cd /mnt/Packages/
[root@oldboy Packages]# rpm -ivh tree-1.5.-.el6.x86_64
[root@oldboy Packages]# mkdir -p /data/{,}/data
[root@oldboy Packages]# tree /data
/data
├──
│   └── data
└──
└── data directories, files

配置mysql配置文件

[root@oldboy Packages]# mv /etc/my.cnf  /etc/my.cnf.bak
[root@oldboy Packages]# cd /application/mysql/support-files/
[root@oldboy support-files]# cp my-small.cnf /etc/my.cnf

再将事先编辑好的两个my.cnf配置文件分别放置到/data/3306/和/data/3307/下,两个 mysql配置文件分别放置到/data/3306/和/data/3307/下(3306和3307的两对配置文件除了端口3306和3307不同,其他完全相同),修改所属组和权限

[root@oldboy ~]# chown -R mysql.mysql /data
[root@oldboy ~]# chmod +x /data/{,}/mysql

3306的my.cnf内容如下

[client]
port=
socket= /data//mysql.sock
[mysql]
no-auto-rehash
[mysqld]
user = mysql
port =
socket = /data//mysql.sock
basedir = /application/mysql
datadir = /data//data
open_files_limit=
back_log =
max_connections =
max_connect_errors =
table_cache =
external-locking = FALSE
max_allowed_packet =8M
sort_buffer_size = 1M
join_buffer_size = 1M
thread_cache_size =
thread_concurrency =
query_cache_size = 2M
query_cache_limit = 1M
query_cache_min_res_unit = 2k
#default_table_type = InnoDB
thread_stack = 192K
#transaction_isolation = READ-COMMITTED
tmp_table_size = 2M
max_heap_table_size = 2M
long_query_time =
#log_long_format
#log-error = /data//error.log
#log-slow-queries =/data//slow.log
pid-file = /data//mysql.pid
log-bin = /data//mysql-bin
relay-log = /data//relay-bin
relay-log-info-file = /data//relay-log.info
binlog_cache_size = 1M
max_binlog_cache_size = 1M
max_binlog_size = 2M
expire_logs_days =
key_buffer_size = 16M
read_buffer_size = 1M
read_rnd_buffer_size = 1M
bulk_insert_buffer_size = 1M
#myisam_sort_buffer_size = 1M
#myisam_max_sort_file_size = 10G
#myisam_max_extra_sort_file_size = 10G
#myisam_repair_threads =
#myisam_recover
lower_case_table_names =
skip-name-resolve
slave-skip-errors = ,
replicate-ignore-db=mysql
server-id =
innodb_additional_mem_pool_size = 4M
innodb_buffer_pool_size = 32M
innodb_data_file_path = ibdata1:128M:autoextend
innodb_file_io_threads =
innodb_thread_concurrency =
innodb_flush_log_at_trx_commit =
innodb_log_buffer_size = 2M
innodb_log_file_size = 4M
innodb_log_files_in_group =
innodb_max_dirty_pages_pct =
innodb_lock_wait_timeout =
innodb_file_per_table =
[mysqldump]
quick
max_allowed_packet = 2M
[mysqld_safe]
log-error=/data//mysql3306.err
pid-file=/data//mysqld.pid

3306的mysql文件内容如下

#!/bin/sh
######################################
######################################
#init
port=
mysql_user="root"
mysql_pwd="oldboy"
CmdPath="/application/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 >& > /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
function_start_mysql
} case $ in
start)
function_start_mysql
;;
stop)
function_stop_mysql
;;
restart)
function_restart_mysql
;;
*)
printf "Usage: /data/${port}/mysql {start|stop|restart}\n"
esac

设置PATH环境变量

[root@oldboy ~]# echo 'export PATH=/application/mysql/bin:$PATH'>>/etc/profile
[root@oldboy ~]# source /etc/profile
[root@oldboy ~]# echo $PATH
/application/mysql/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

安装两个mysql实例,出现两个ok表示此步骤没有问题

[root@oldboy ~]# cd /application/mysql/scripts/
[root@oldboy scripts]# ./mysql_install_db --basedir=/application/mysql --datadir=/data//data --user=mysql
…………………
Installing MySQL system tables...
:: [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
:: [Note] /application/mysql/bin/mysqld (mysqld 5.5.) starting as process ...
OK
Filling help tables...
:: [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
:: [Note] /application/mysql/bin/mysqld (mysqld 5.5.) starting as process ...
OK
…………………
[root@oldboy scripts]# ./mysql_install_db --basedir=/application/mysql --datadir=/data//data --user=mysql
…………………
Installing MySQL system tables...
:: [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
:: [Note] /application/mysql/bin/mysqld (mysqld 5.5.) starting as process ...
OK
Filling help tables...
:: [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
:: [Note] /application/mysql/bin/mysqld (mysqld 5.5.) starting as process ...
OK
…………………

启动mysql实例,先启动3306实例

[root@oldboy scripts]# /data//mysql start
Starting MySQL...
[root@oldboy scripts]# :: mysqld_safe error: log-error set to '/data/3306/mysql3306.err', however file don't exists. Create writable for user 'mysql'.

上面报log-error '/data/3306/mysql3306.err'不能存在,那么创建

[root@oldboy scripts]#  cd /data
[root@oldboy data]# touch /mysql3306.err
[root@oldboy data]# touch /mysql3307.err
[root@oldboy data]# chown mysql.mysql /mysql3306.err
[root@oldboy data]# chown mysql.mysql /mysql3307.err

再分别启动和登录登录两个实例,启动后通过netstat -lntup查看启动情况,多实例登录时需要通过-S指定sock文件,且初次登录没有密码

[root@oldboy data]# /data//mysql start
Starting MySQL...
[root@oldboy data]# /data//mysql start
Starting MySQL...
[root@oldboy ]# netstat -lntup|grep
tcp 0.0.0.0: 0.0.0.0:* LISTEN /mysqld
tcp 0.0.0.0: 0.0.0.0:* LISTEN /mysqld
[root@oldboy data]# mysql -S /data//mysql.sock (无密码登录)
[root@oldboy data]# mysql -S /data//mysql.sock (无密码登录)

通过/application/mysql/bin下的mysqladmin命令给两个实例设置root密码,再通过密码登录mysql

[root@oldboy data]# mysqladmin -u root -S /data//mysql.sock password "oldboy"
[root@oldboy data]# mysqladmin -u root -S /data//mysql.sock password "oldboy"
[root@oldboy data]# mysql -uroot -poldboy -S /data//mysql.sock(有密码登录)
mysql> system mysql -uroot -poldboy -S /data//mysql.sock(在3306实例中通过system系统命令切换到3307实例)

设置多实例开机自启动

[root@oldboy data]# echo "#mysql multi instance start when system starting" >>/etc/rc.local
[root@oldboy data]# echo "/data/3306/mysql start" >>/etc/rc.local
[root@oldboy data]# echo "/data/3307/mysql start" >>/etc/rc.local
[root@oldboy data]# tail - /etc/rc.local
tail: inotify cannot be used, reverting to polling
#mysql multi instance start when system starting
/data//mysql start
/data//mysql start

centos6安装多实例mysql的更多相关文章

  1. 一台Ubuntu server上安装多实例MySQL

    受环境所迫,在一台Ubuntu server上安装多个实例MySQL. 手动安装MySQL 环境:Ubuntu server 11.10 64bit + mysql-5.5.17-linux2.6-x ...

  2. 【MySQL】源码编译安装和配置MySql 5.5.32(单实例)

    [需求描述] 在CentOS环境中,通过编译源码的方式,安装并且配置“单实例”的MySQL5.5.32数据库. MySQL的安装目录为:/application/mysql-5.5.32 MySQL数 ...

  3. CentOS6.5下源码安装多个MySQL实例及复制搭建

    多实例安装本节是在CentOS6.5下源码安装MySQL5.6.35的基础上,在同一台机器增加一个MySQL实例.参考Centos中安装多个mysql数据的配置实例,安装目录为/usr/local/m ...

  4. CentOS6.0(64位)安装Apache+PHP+Mysql教程,安装Magento(解决DOM,Mcrypt,GD问题)完整教程

    CentOS6.0(64位)安装Apache+PHP+Mysql教程,安装Magento(解决DOM,Mcrypt,GD问题)完整教程 0   Posted by :小黑 On : 2012 年 9 ...

  5. centos6 安装mysql

    如果要在Linux上做j2ee开发,首先得搭建好j2ee的开发环境,包括了jdk.tomcat.eclipse的安装(这个在之前的一篇随笔中已经有详细讲解了Linux学习之CentOS(七)--Cen ...

  6. CentOS6.7下使用非root用户(普通用户)编译安装与配置mysql数据库并使用shell脚本定时任务方式实现mysql数据库服务随机自动启动

    CentOS6.7下使用非root用户(普通用户)编译安装与配置mysql数据库并使用shell脚本定时任务方式实现mysql数据库服务随机自动启动1.关于mysql?MySQL是一个关系型数据库管理 ...

  7. 如何在同一台机器上安装多个MySQL的实例

    转自:'http://www.cnblogs.com/shangzekai/p/4375271.html 最近由于工作的需要,需要在同一台机器上搭建两个MySQL的实例,(注:已经存在了一个3306的 ...

  8. 同一台windows下配置安装多个mysql实例,实现主从同步

    一.安装多个mysql 参见: https://blog.csdn.net/wrh_csdn/article/details/80198795 https://www.cnblogs.com/qjoa ...

  9. MySQL 在Windows平台上的安装及实例多开

    MySQL在Windows平台上的安装及实例多开   by:授客 QQ:1033553122 测试环境 Win7 64 mysql-5.7.20-winx64.zip 下载地址: https://cd ...

随机推荐

  1. windows 邮槽mailslot 在服务程序内建立后客户端无权限访问(GetLastError() == 5)的问题

    邮槽创建在服务程序内,可以创建成功, 但外部客户端连接时 m_hMailslot = CreateFile("\\\\.\\mailslot\\zdpMailslot",GENER ...

  2. [Java in NetBeans] Lesson 02. Variables, Data Types and Assignment.

    这个课程的参考视频在youtube. 主要学到的知识点有: Data Type: int, char, String, double, boolean. When into printf, int ( ...

  3. js图的数据结构处理----邻链表,广度优先搜索,最小路径,深度优先搜索,探索时间拓扑

    //邻居连表 //先加入各顶点,然后加入边 //队列 var Queue = (function(){ var item = new WeakMap(); class Queue{ construct ...

  4. Elasticsearch5.x批量插入数据(Java)

    先上官方示例代码:官方示例 Java代码: // 批量插入数据 public void InsertBatch() { try { // 设置集群名称 Settings settings = Sett ...

  5. @responsebody 返回json

    添加jackson依赖 添加@ResponseBody 测试:  注意,如果输入中文,出现乱码现象,则需要@RequestMapping(value="/appinterface" ...

  6. GE与POST方法区别

    1.用途. GET方法一般用于查询并获取信息,这意味着它是幂等的(对同一个url的多个请求,返回结果完全一样),因为没有修改资源状态,所以它是安全的.而POST一般用于更新资源信息,既不是幂等,也不是 ...

  7. JavaScript三种判断语句和三元运算符

    三种判断语句 1.if结构 语法:if(条件){条件满足时执行的代码块} 2.if else结构 语法:if(条件){条件满足时执行的代码块}   else{条件不满足时执行的代码块} 3.if el ...

  8. B树,B+树,B*树以及R树的介绍

    https://blog.csdn.net/peterchan88/article/details/52248714 作者:July.weedge.Frankie.编程艺术室出品. 说明:本文从B树开 ...

  9. wingide 远程调试

    1.首先你应该在本地安装wingide 6.1版本 2.大多数电脑.py文件都不能以wingide的形式打开(异常苦逼),无论是从“属性”或者是“设置”里面都不可以,无奈之下只能通过修改注册表的方式进 ...

  10. vs实现数据库数据迁移

    public ActionResult About() { List<ChangeData.Models.old.adsinfo> adsinfo_new = new List<Mo ...