MySQL多實(shí)例安裝

1. 服務(wù)器時(shí)間同步
[root@linux1 ~]# ntpdate  time.nuri.net
2. MySQL官網(wǎng)下載相應(yīng)的二進(jìn)制包并且安裝

下載鏈接:http://dev.mysql.com/downloads/mysql/
將下載好的MySQL二進(jìn)制包上傳到服務(wù)器

2.1 創(chuàng)建MySQL用戶mysql以便于啟動程序使用
[root@linux1 ~]# useradd mysql -s /sbin/nologin  -M
2.2 解壓復(fù)制到默認(rèn)安裝路徑/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/下方便啟動的時(shí)候指定配置文件,同時(shí)刪除默認(rèn)配置文件/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 #指定數(shù)據(jù)庫存放路徑
port = 3306 #指定端口號
server_id = 129 #設(shè)置為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 復(fù)制bin文件到系統(tǒng)PATH路徑
[root@linux1 mysql]# cp bin/* /usr/bin/
2.6 初始化安裝MySQL,并授權(quán)data文件夾權(quán)限
[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數(shù)據(jù)庫
因?yàn)槭嵌鄬?shí)例安裝所以需要指定配置文件和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 多實(shí)例MySQL_Slave安裝

安裝步驟同上,需要注意一下幾點(diǎn):

  • 配置文件中的basedir,datadir,server_id,socket,port需要修改
  • 配置文件存放在mysql_slave目錄下
  • 啟動時(shí)候指定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. 查看多實(shí)例是否已經(jīng)啟動
[root@linux1 ~]# netstat -lntup | grep mysql
tcp        0      0 :::3306                     :::*                        LISTEN      1855/mysqld         
tcp        0      0 :::3307                     :::*                        LISTEN      2477/mysqld 
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容