博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mysql主从
阅读量:6328 次
发布时间:2019-06-22

本文共 4768 字,大约阅读时间需要 15 分钟。

一、实验环境

1、IP与主机名
192.168.10.51   db1.linuxbrother.com master
192.168.10.52 db2.linuxbrother.com slave
2、所需软件
mysql-5.1.63.tar.gz
3、安装gcc和相应的依赖包
[root@db1 ~]# yum -y install gcc ncurses-devel libtool
二、Master配置
1、安装Mysql
[root@db1 ~]# tar -zxvf mysql-5.1.63.tar.gz -C /usr/src/
[root@db1 ~]# useradd -M -s /sbin/nologin mysql
[root@db1 ~]# cd /usr/src/mysql-5.1.63/
[root@db1 mysql-5.1.63]# vim configure   #把下面行注释掉
52297 #    $RM "$cfgfile"
[root@db1 mysql-5.1.63]# ./configure --prefix=/usr/local/mysql/ --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=innobase --with-mysqld-user=mysql
[root@db1 mysql-5.1.63]# make
[root@db1 mysql-5.1.63]# make install
[root@db1 mysql-5.1.63]# cp support-files/my-medium.cnf /usr/local/mysql/my.cnf
[root@db1 mysql-5.1.63]# /usr/local/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data 
[root@db1 mysql-5.1.63]# chown -R root.mysql /usr/local/mysql
[root@db1 mysql-5.1.63]# chown -R mysql /usr/local/mysql/data/
[root@db1 mysql-5.1.63]# echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf  
[root@db1 mysql-5.1.63]# ldconfig 
[root@db1 mysql-5.1.63]# echo "export PATH=/usr/local/mysql/bin:$PATH" >> /etc/profile
[root@db1 mysql-5.1.63]# source /etc/profile
[root@db1 mysql-5.1.63]# mkdir /usr/local/mysql/tmp
[root@db1 mysql-5.1.63]# chmod 777 /usr/local/mysql/tmp/
[root@db1 mysql-5.1.63]# vim /usr/local/mysql/my.cnf  #修改socket位置
socket          = /usr/local/mysql/tmp/mysql.sock
[root@db1 mysql-5.1.63]# mysqld_safe --defaults-file=/usr/local/mysql/my.cnf &
[root@db1 mysql-5.1.63]# mysql -uroot -p --socket=/usr/local/mysql/tmp/mysql.sock 
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.1.63-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> grant replication slave on *.* to  identified by 'backuppwd';

Query OK, 0 rows affected (0.00 sec)
mysql> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000002 |      265 |              |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
三、Slave配置
安装过程如上,步骤省略......
[root@db2 mysql-5.1.63]# vim /usr/local/mysql/my.cnf   #修改server-id
server-id       = 2
[root@db2 mysql-5.1.63]# mysqld_safe --defaults-file=/usr/local/mysql/my.cnf &
[root@db2 mysql-5.1.63]# mysql -uroot -p --socket=/usr/local/mysql/tmp/mysql.sock 
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.63-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> change master to master_host='192.168.10.51',master_user='backup',master_password='backuppwd',master_log_file='mysql-bin.000002',master_log_pos=265;

Query OK, 0 rows affected (0.24 sec)

mysql> start slave;

Query OK, 0 rows affected (0.02 sec)

mysql> show slave status\G

......
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
......
四、验证
1、在Master上面操作
[root@db1 mysql-5.1.63]# mysql -uroot -p --socket=/usr/local/mysql/tmp/mysql.sock 
mysql> create database mysqltest;
Query OK, 1 row affected (0.00 sec)

mysql> use mysqltest;

Database changed
mysql> create table user (id int(5),name char(10));
Query OK, 0 rows affected (0.00 sec)

mysql> insert into user values (0001,'xieping');

Query OK, 1 row affected (0.00 sec)

mysql> insert into user values (0002,'huxinxin');

Query OK, 1 row affected (0.00 sec)

mysql> insert into user values (0003,'dingpeng');

Query OK, 1 row affected (0.00 sec)
2、在Slave上操作
[root@db2 mysql-5.1.63]# mysql -uroot -p --socket=/usr/local/mysql/tmp/mysql.sock 
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| mysqltest          |
| test               |
+--------------------+
4 rows in set (0.02 sec)

mysql> select id,name from mysqltest.user;

+------+----------+
| id   | name     |
+------+----------+
|    1 | xieping  |
|    2 | huxinxin |
|    3 | dingpeng |
+------+----------+
3 rows in set (0.00 sec)

本文转自谢无赖51CTO博客,原文链接:http://blog.51cto.com/xieping/925377 ,如需转载请自行联系原作者

你可能感兴趣的文章
Linux内核同步:RCU
查看>>
Android逆向进阶——让你自由自在脱壳的热身运动(dex篇)
查看>>
Java设计模式之五大创建型模式(附实例和详解)
查看>>
60 Permutation Sequence
查看>>
主流的RPC框架有哪些
查看>>
Hive学习之路 (七)Hive的DDL操作
查看>>
[转]mysql使用关键字作为列名的处理方式
查看>>
awesome go library 库,推荐使用的golang库
查看>>
树形展示形式的论坛
查看>>
jdbcTemplate 调用存储过程。 入参 array 返回 cursor
查看>>
C++中的stack类、QT中的QStack类
查看>>
Linux常用基本命令[cp]
查看>>
CSS 相对|绝对(relative/absolute)定位系列(一)
查看>>
关于 Nginx 配置 WebSocket 400 问题
查看>>
Glide和Govendor安装和使用
查看>>
Java全角、半角字符的关系以及转换
查看>>
Dubbo和Zookeeper
查看>>
前端项目课程3 jquery1.8.3到1.11.1有了哪些新改变
查看>>
UOJ#179. 线性规划(线性规划)
查看>>
整合spring cloud云架构 - SSO单点登录之OAuth2.0登录认证(1)
查看>>