MySQL多实例安装

1. 服务器时间同步
[root@linux1 ~]# ntpdate  time.nuri.net
2. MySQL官网下载相应的二进制包并且安装

下载链接:http://dev.mysql.com/downloads/mysql/
将下载好的MySQL二进制包上传到服务器

2.1 创建MySQL用户mysql以便于启动程序使用
[root@linux1 ~]# useradd mysql -s /sbin/nologin  -M
2.2 解压复制到默认安装路径/usr/local/mysql下
[root@linux1 ~]# tar zxvf mysql-5.6.32-linux-glibc2.5-x86_64.tar.gz
[root@linux1 ~]# cp -R mysql-5.6.32-linux-glibc2.5-x86_64 /usr/local/mysql
[root@linux1 ~]# rm -rf /rtc/my.cnf
2.3 将/usr/local/mysql/support-files/my-default.cnf文件copy到/usr/local/mysql/下方便启动的时候指定配置文件,同时删除默认配置文件/etc/my.cnf
[root@linux1 ~]# cd /usr/local/mysql/
[root@linux1 mysql]# cp support-files/my-default.cnf ./my.cnf
2.4 编辑my.cnf文件
[root@linux1 mysql]# vim my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql #指定安装文件路径
datadir = /usr/local/mysql/data #指定数据库存放路径
port = 3306 #指定端口号
server_id = 129 #设置为IP地址最后位
socket = /tmp/mysql.sock #socket通信文件

# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 
2.5 复制bin文件到系统PATH路径
[root@linux1 mysql]# cp bin/* /usr/bin/
2.6 初始化安装MySQL,并授权data文件夹权限
[root@linux1 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data/ --basedir=/usr/local/mysql/
[root@linux1 mysql]# chown -R mysql:mysql data/

#######2.7 启动MySQL数据库
因为是多实例安装所以需要指定配置文件和socket文件

[root@linux1 mysql]# mysqld_safe --defaults-file=/usr/local/mysql/my.cnf &
[1] 1711
[root@linux1 mysql]# 161124 21:55:20 mysqld_safe Logging to '/usr/local/mysql/data/linux1.err'.
161124 21:55:21 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
[root@linux1 ~]# mysqladmin -uroot password -S /tmp/mysql.sock 
New password: 
Confirm new password: 
[root@linux1 ~]# mysql -uroot -p -S /tmp/mysql.sock 
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.32 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
3 多实例MySQL_Slave安装

安装步骤同上,需要注意一下几点:

  • 配置文件中的basedir,datadir,server_id,socket,port需要修改
  • 配置文件存放在mysql_slave目录下
  • 启动时候指定slave的sock文件和配置文件
[root@linux1 ~]# mv mysql-5.6.32-linux-glibc2.5-x86_64/ /usr/local/mysql_slave
[root@linux1 ~]# cd /usr/local/mysql_slave/
[root@linux1 mysql_slave]# cp support-files/my-default.cnf ./my.cnf
[root@linux1 mysql_slave]# vim my
basedir = /usr/local/mysql_slave
datadir = /usr/local/mysql_slave/data
port = 3307
server_id = 130
socket = /tmp/mysql_slave.sock

[root@linux1 mysql_slave]# chown -R mysql:mysql data/
[root@linux1 mysql_slave]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql_slave/ --datadir=/usr/local/mysql_slave/data/
[root@linux1 mysql_slave]# mysqld_safe --defaults-file=/usr/local/mysql_slave/my.cnf  &
161125 11:18:50 mysqld_safe Logging to '/usr/local/mysql_slave/data/linux1.err'.
161125 11:18:50 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql_slave/data
[root@linux1 ~]# mysqladmin -uroot password -S /tmp/mysql_slave.sock 
New password: 
Confirm new password: 
[root@linux1 ~]# mysql -uroot -p -S /tmp/mysql_slave.sock 
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.32 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
4. 查看多实例是否已经启动
[root@linux1 ~]# netstat -lntup | grep mysql
tcp        0      0 :::3306                     :::*                        LISTEN      1855/mysqld         
tcp        0      0 :::3307                     :::*                        LISTEN      2477/mysqld 
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 229,362评论 6 537
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 99,013评论 3 423
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 177,346评论 0 382
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 63,421评论 1 316
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 72,146评论 6 410
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 55,534评论 1 325
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 43,585评论 3 444
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 42,767评论 0 289
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 49,318评论 1 335
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 41,074评论 3 356
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 43,258评论 1 371
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 38,828评论 5 362
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 44,486评论 3 347
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 34,916评论 0 28
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 36,156评论 1 290
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 51,993评论 3 395
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 48,234评论 2 375

推荐阅读更多精彩内容