LINUX 下mysql主从安装与同步
两台服务器
主:172.16.0.120 Master120
从:172.16.0.121 backup121
两台都要安装mysql如下步骤
安装系统所需要的依赖包
[root@ Master120 ~]# yum -y install gcc gcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* cmake bison
创建mysql用户与用户组
[root@ Master120 ~]# groupadd mysql
[root@ Master120 ~]# useradd -r -g mysql mysql
安装mysql
[root@ Master120 ~]# tar zxvf mysql-5.5.25.tar.gz
[root@ Master120 ~]# cd mysql-5.5.25
[root@Master120 mysql-5.5.25]# cmake -DCMAKE_INSTALL_PREFIX=/opt/mysql/ -DMYSQL_DATADIR=/opt/mysql/data -DMYSQL_UNIX_ADDR=/opt/mysql/data/mysqld.sock -DWITH_INNOBASE_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_TCP_PORT=3306 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_UNIX_ADDR=/opt/mysql/data/mysql.sock -DMYSQL_USER=mysql -DWITH_DEBUG=0
[root@ Master120 mysql-5.5.25]# make && make install
赋予相关权限
[root@ Master120 mysql-5.5.25]# chown -R mysql:mysql /opt/mysql
[root@Master120 mysql-5.5.25]# /opt/mysql/scripts/mysql_install_db --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data
mysql配置文件
[root@ Master120 mysql-5.5.25]# cp /opt/mysql/support-files/my-large.cnf /etc/my.cnf
[root@Master120 mysql-5.5.25]# cp /opt/mysql/support-files/mysql.server /etc/init.d/mysql
[root@Master120 mysql-5.5.25]# chmod +x /etc/init.d/mysql
增加自动启动
[root@Master120 mysql-5.5.25]# chkconfig mysql on
启动mysql
[root@Master120 mysql-5.5.25]# /etc/init.d/mysql start
Starting MySQL...... [ OK ]
查看mysql 的3306端口,看到下面说明启动成功
[root@Master120 mysql-5.5.25]#ps aux | grep 3306
mysql 17237 3.6 8.4 615660 86264 pts/2 Sl 22:10 0:01 /opt/mysql/bin/mysqld --basedir=/opt/mysql --datadir=/opt/mysql/data --plugin-dir=/opt/mysql/lib/plugin --user=mysql --log-error=/opt/mysql/data/Master120.err --pid-file=/opt/mysql/data/Master120.pid --socket=/opt/mysql/data/mysql.sock --port=3306
root 17798 0.0 0.0 61228 784 pts/2 S+ 22:10 0:00 grep 3306
设置mysql初始密码,123456是密码,你可以设置自己需要的密码
[root@Master120 mysql-5.5.25]# /opt/mysql/bin/mysqladmin -u root password '123456'
[root@Master120 mysql-5.5.25]# /opt/mysql/bin/mysql -uroot -p123456
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.25-log Source distribution
Copyright (c) 2000, 2011, 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>
主从复制的配置
主的my.cnf的server-id=1,每个同步服务都必须设定一个唯一的编号。
在Master(这里为Master120机器)上增加一个用于复制的账号:
mysql>GRANT REPLICATION SLAVE ON *.* TO 'repl'@'172.16.0.%' IDENTIFIED BY '123456';
mysql>FLUSH REPLICATION;
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 | 245 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
设置Slave 主机
修改my.cnf的server-id,内容如下:
backup121主机
server-id=2
开启Master与Slave的同步
在Slave上执行如下命令
mysql>CHANGE MASTER TO MASTER_HOST='172.16.0.120',
->MASTER_USER='repl',
->MASTER_PASSWORD='123456',
->MASTER_LOG_FILE='mysql-bin.000001',
->MASTER_LOG_POS=245;
之后执行
mysql>slave start;
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 172.16.0.120
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 245
Relay_Log_File: backup121-relay-bin.000001
Relay_Log_Pos: 253
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 245
Relay_Log_Space: 556
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
1 row in set (0.00 sec)
看到都为yes,说明成功
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
注意防火墙,关闭防火墙或者增加3306端口对外访问
如果在生产库中从库同步出错我们可以在从库的my.cnf增加Slave_skip_errors =all 跳过全部错误。
LINUX 下mysql主从安装与同步相关推荐
- linux下mysql(rpm)安装使用手册
linux下mysql(rpm)安装使用手册 安装Mysql 1.下载MySQL的安装文件 安装MySQL需要下面两个文件: MySQL-server-5.1.7-0.i386.rpm 下载地址为:h ...
- windows下mysql和linux下mysql主从配置
1. linux下mysql安装版本5.6 windows下mysql版本5.7 不要问我为什么版本不一致 就是想这么搞 2. linux为主服务器 windows为从服务器 3.找到li ...
- linux下Mysql 的安装、配置、数据导入导出
为什么80%的码农都做不了架构师?>>> <p><span>MySQL</span><span>是一种</span> ...
- Linux下MySQL的安装与使用
安装前 工具 Centos7 Xshell Xftp 查看是否安装过MySQL 如果你是用rpm安装, 检查一下RPM PACKAGE: rpm -qa | grep -i mysql # -i 忽略 ...
- Linux下MySQL主从架构版本升级(5.7.31->5.7.33)——冷升级
目录 前言 下载并上传MySQL 停应用 升级从库 停止备份 停止从MySQL 继承旧版本的配置 启动并升级从MySQL 登录并验证slave 关闭slave 升级主库 查看master状态 修改从库 ...
- (0.2)linux下Mysql的安装配置与管理入门(目录篇)
本章学习内容: 1.基于Linux平台的Mysql项目场景介绍 1.1.互联网各类网站.购物网站.门户网站.博客系统.IDC,云平台,VPS,虚拟主机空间,论坛,嵌入式. 2.mysql数据库运行环境 ...
- Linux下mySql的安装和使用
1.安装mysql groupadd mysql 建立mysql分组(方便管理) useradd -g mysql mysql 创建用户mysql到mysql组里 scripts/mysql_in ...
- linux下mysql默认安装目录和常用命令
MySQL安装完成后不象SQL Server默认安装在一个目录,它的数据库文件.配置文件和命令文件分别在不同的目录,了解这些目录非常重要,尤其对于Linux的初学者,因为 Linux本身的目录结构就比 ...
- Linux下Mysql卸载安装教程:卸载老版本,安装新版本
由于:练习Mysql的主从复制,保证Mysql的版本一致,所以更新Linux上的Mysql版本 第一步:卸载linux系统上的原来的版本的mysql: 1.使用命令行查询电脑上的版本: rpm -qa ...
最新文章
- 详细透彻的分析DM9000网卡驱动程序(4)
- Linux线程-互斥锁pthread_mutex_t
- erlang的lists笔记
- WINDOWS2003域控制器禁止U盘
- 【PAT乙级】1003 我要通过! (20 分)详解
- Windows -- cmd命令: ipconfig 和 nbtstat
- devexpress gridcontrol 内置导航栏,双击后才修改数据
- 小甲鱼 OllyDbg 教程系列 (八) :fjproducer 逆向 之 困境
- 数学模型让咖啡更好喝
- mysql在单片机移植_移植MySQL到嵌入式ARM平台
- bootstrap table 表格支持shirt 多选_bootstrap-table 表格行内编辑实现
- Preference Learning——Object Ranking
- JavaScript表单基本验证
- 苹果开发---window配置苹果虚拟机 和安装xcode
- matlab反激变换器仿真模型,基于MATLAB的反激变换器分析与设计-毕业设计.docx
- Python实现聊天机器人
- 27_ArrayList类
- 父亲发现高三女儿早恋 机智做法让网友惊呆
- windows10上安装mysql(详细步骤)
- 计算机睡眠伤硬盘,放开那块硬盘!聊聊Win8伤盘那些事
热门文章
- 数据库-使用Command对象进行数据库查询
- JavaScript版代码执行
- 物联网项目开发工作笔记0001---物联网项目的开发周期,项目管理,厂家合作
- android学习笔记---51_编码实现软件界面,把固定不变的界面写到xml中,逻辑改变的写到程序中,
- 2015年4月1号 的日志
- sftp服务器存放机密文件,cetos 6.6搭建sftp服务
- linux驱动编写(dma驱动)
- **Dijkstra算法**
- Markdown编辑器的使用技巧
- net修复工具_Stimulsoft Ultimate v2020.3.2修复性更新升级!| 附下载