【mysql主从搭建(二进制脚本安装)】怀抱观古今,寝食展戏谑。这篇文章主要讲述mysql主从搭建(二进制脚本安装)相关的知识,希望能为你提供帮助。
1.二进制方式脚本安装mysql1.1.准备文件
配置文件:my.cnf
安装包:mysql-5.6.42-linux-glibc2.12-x86_64.tar.gz
安装脚本:mysql-install.sh
1.2.my.cnf
[mysqld]
socket=/data/mysql/mysql.sock
user=mysql
symbolic-links=0
datadir=/data/mysql
innodb_file_per_table=1
max_connections=10000
[client]
port=3306
socket=/var/lib/mysql/mysql.sock
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/tmp/mysql.sock
1.3.mysql-install.sh
#!/bin/bash
DIR=`pwd`
NAME="mysql-5.6.42-linux-glibc2.12-x86_64.tar.gz"
FULL_NAME=$DIR/$NAME
DATA_DIR="/data/mysql"
apt-get install libaio* -y
if [ -f $FULL_NAME ]; then
echo "安装文件存在"
else
echo "安装文件不存在"
exit 3
fi
if [ -h /usr/local/mysql ]; then
echo "Mysql 已经安装"
exit 3
else
tar xvf $FULL_NAME-C /usr/local/src
ln -sv /usr/local/src/mysql-5.6.42-linux-glibc2.12-x86_64/usr/local/mysql
if idmysql; then
echo "mysql 用户已经存在,跳过创建用户过程"
else
useraddmysql-s /sbin/nologin
fi
ifidmysql; then
chown-R mysql.mysql/usr/local/mysql/* -R
if [ ! -d/data/mysql ]; then
mkdir -pv /data/mysql /var/lib/mysql & & chown-R mysql.mysql/data/mysql-R
/usr/local/mysql/scripts/mysql_install_db--user=mysql --datadir=/data/mysql--basedir=/usr/local/mysql/
cp/usr/local/src/mysql-5.6.42-linux-glibc2.12-x86_64/support-files/mysql.server /etc/init.d/mysqld
chmod a+x /etc/init.d/mysqld
cp $DIR/my.cnf/etc/my.cnf
ln -sv /usr/local/mysql/bin/mysql/usr/bin/mysql
ln -sv /data/mysql/mysql.sock/var/lib/mysql/mysql.sock
/etc/init.d/mysqld start
else
echo "MySQL数据目录已经存在,"
exit 3
fi
fi
fi
2.主数据库配置2.1.配置文件修改
vim /etc/my.cnf
-------------------------------------
server_id=53
log_bin=/data/logbin/mysql_bin_log #注意/data/logbin/目录权限,改为mysql
-------------------------------------
systemctl daemon-reload
2.2.授权及用户创建
mysql> GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO rsync-user@192.168.47.% IDENTIFIED BY 123456;
2.3.测试
#创建一个库测试
create database taowenwu;
2.4.查看二进制Position
mysql> show master status;
+----------------------+----------+--------------+------------------+-------------------+
| File| Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+----------------------+----------+--------------+------------------+-------------------+
| mysql_bin_log.000001 |309 ||||
+----------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
2.5.备份
/usr/local/mysql/bin/mysqldump --all-databases --single_transaction --flush-logs --master-data=https://www.songbingjia.com/android/2 --lock-tables > /data/backup.sql
scp /data/backup.sql 192.168.47.54:/data/
3.从数据库配置3.1.配置文件修改
vim /etc/my.cnf
-------------------------------------
server_id=54
-------------------------------------
3.2.数据还原
root@ubuntu:/data# mysql < /data/backup.sql
3.3.使用有复制权限的用户账号连接至主服务器,并启动复制线程
CHANGE MASTER TO MASTER_HOST=192.168.47.53, \\
MASTER_USER=rsync-user,MASTER_PASSWORD=123456, \\
MASTER_LOG_FILE=mysql_bin_log.000001,MASTER_LOG_POS=309;
#启动
START SLAVE
3.4.查看
mysql> show slave status\\G;
推荐阅读
- 一图看懂pod亲和性调度策略,再也不担心学不废了!
- nginx光速入门到进阶
- centos7 安装高版本cmake 3.2 避 cmake: command not found坑
- linux 秘钥登录,不要密码
- 虚拟机如何上网
- tomcat安装脚本
- Navicat远程连接Linux下的mariadb数据库
- Windows Server 2008R2 降级失败,提示目录服务没有必须的配置信息,2022,2091日志
- 可以一键迁移到人人站吗()