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
网友评论