【转载】MySQL Replication 环境安装与配置

安装
[[email protected] ~]# yum install mysql-server
Installed:
mysql-server.x86_64 0:5.1.73-3.el6_5

Dependency Installed:
mysql.x86_64 0:5.1.73-3.el6_5
perl-DBD-MySQL.x86_64 0:4.013-3.el6
perl-DBI.x86_64 0:1.609-4.el6

启动并修改密码
[[email protected] ~]# service mysqld start

Please report any problems with the /usr/bin/mysqlbug script!

[ OK ]
Starting mysqld: [ OK ]
[[email protected] ~]# /usr/bin/mysqladmin -u root password ‘mysqlpass’
[[email protected] ~]#
查看默认的my.cnf配置
[[email protected] ~]# cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[[email protected] ~]#

修改主服务器my.cnf配置
[[email protected] ~]# vi /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

server-id=1
log-bin=mysql-bin
binlog-ignore-db=mysql

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
在主数据库中增加复制用户并授权
mysql> grant replication slave on *.* to ‘msrslave’@’192.168.197.86’ identified by ‘slavepasswd’;
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> show master status;
+——————+———-+————–+——————+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+——————+———-+————–+——————+
| mysql-bin.000001 | 106 | | mysql |
+——————+———-+————–+——————+
1 row in set (0.00 sec)

mysql> exit

修改从服务器my.cnf配置文件
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

server-id=2
log-bin=mysql-bin
replicate-ignore-db=mysql

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
停止slave线程并配置连接master
mysql> stop slave;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> change master to master_host=’192.168.197.85′,master_user=’msrslave’,master_password=’slavepasswd’;
Query OK, 0 rows affected (0.16 sec)

mysql>

在主服务器上开启3306端口
[[email protected] ~]# iptables -I INPUT -p tcp –dport 3306 -j ACCEPT
[[email protected] ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
[[email protected] ~]#

重新启动slave服务器
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

查看slave运行状态
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Connecting to master
Master_Host: 192.168.197.85
Master_User: msrslave
Master_Port: 3306
Connect_Retry: 60
Master_Log_File:
Read_Master_Log_Pos: 4
Relay_Log_File: mysqld-relay-bin.000001
Relay_Log_Pos: 4
Relay_Master_Log_File:
Slave_IO_Running: No
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB: mysql
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: 0
Relay_Log_Space: 106
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: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 2013
Last_IO_Error: error connecting to master ‘[email protected]:3306′ – retry-time: 60 retries: 86400
Last_SQL_Errno: 0
Last_SQL_Error:
1 row in set (0.00 sec)

ERROR:
No query specified

mysql>
在主服务器上建立新数据库并导入数据
mysql> create database linuxcache;
Query OK, 1 row affected (0.00 sec)

mysql> grant all on linuxcache.* to linuxcache;
Query OK, 0 rows affected (0.02 sec)

mysql> grant all on linuxcache.* to [email protected]’%’;
Query OK, 0 rows affected (0.01 sec)

mysql> set password for [email protected]’%’=password(‘lcpasswd’);
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
[[email protected] ~]# mysql -u root -pmysqlpass linuxcache < linuxcache.05_06_14.sql

在从服务器上查看复制生成的数据库
[[email protected] ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 5.1.73-log Source distribution

Copyright (c) 2000, 2013, 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> show databases;
+——————–+
| Database |
+——————–+
| information_schema |
| mysql |
| linucache |
| test |
+——————–+
4 rows in set (0.00 sec)

mysql>

原文地址:http://www.linuxcache.com/archives/2663

转载请注明原文地址

时间: 2024-12-13 08:26:23

【转载】MySQL Replication 环境安装与配置的相关文章

MySQL集群安装与配置

MySQL集群安装与配置 文章目录 [隐藏] 一.mysql集群安装 二.节点配置 三.首次启动节点 四.测试服务是否正常 五.安全关闭和重启 MySQL Cluster 是 MySQL 适合于分布式计算环境的高实用.高冗余版本.它采用了NDB Cluster 存储引擎,允许在1个 Cluster 中运行多个MySQL服务器.MySQL Cluster 能够使用多种故障切换和负载平衡选项配置NDB存储引擎,但在 Cluster 级别上的存储引擎上做这个最简单.下面我们简单介绍MySQL Clus

Linux学习之CentOS--CentOS6.4下Mysql数据库的安装与配置【转】

如果要在Linux上做j2ee开发,首先得搭建好j2ee的开发环境,包括了jdk.tomcat.eclipse的安装(这个在之前的一篇随笔中已经有详细讲解了Linux学习之CentOS(七)--CentOS下j2ee环境搭建),如果要开发web项目,我们当然可以安装一个myeclipse到Linux系统上去,这个安装方法和安装eclipse完全相同,就没有记录下来了,有了jdk.tomcat.eclipse我们就已经能进行我们的程序开发了,但是如果要做一个项目,哪怕是小的不能再小的项目都离不开数

Eclipse 环境安装和配置优化

1.下载相应的eclipse版本.    官方下载地址:http://www.eclipse.org/downloads/    juno版本的64位下载地址:http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/juno/SR2/eclipse-jee-juno-SR2-win32-x86_64.zip 2.解压eclipse-jee-juno-SR2-win32-x86_64.

Linux Debian 下LNMP服务器——nginx+mysql+php环境搭建及配置

昨天刚给公司服务器装了LNMP服务器环境,在这里简单记录一下过程备忘. 这里我在安装的时候是用的Dotdeb源,仅供参考. 1.导入Dotdeb源,据说Dotdeb源里的软件版本比较新. 在向源中导入Dotdeb前,我们需要先获取GnuPG key并导入: wget http://www.dotdeb.org/dotdeb.gpg cat dotdeb.gpg | apt-key add - 提示OK,表明导入成功.然后我们开始导入Dotdeb源,源列表的位置在“/etc/apt/sources

C# 制作Java +Mysql+Tomcat 环境安装程序,一键式安装

原文:C# 制作Java +Mysql+Tomcat 环境安装程序,一键式安装 要求: JDK.Mysql.Tomcat三者制作成一个安装包, 不能单独安装,安装过程不显示三者的界面, 安装完成要配置好JDK环境.Mysql服务.Tomcat 服务 目的: 解决客户在安装软件的复杂配置和繁琐 便于管理软件版本 便于系统集成 分析: 由于不能使用软件的原始安装版本,故只能将JDK的安装目录拷贝出来,放在D盘的SoftSource文件夹,由于要管理三者,将这三个放进一个文件夹里面 Mysql.Tom

macOS下MySQL 8.0 安装与配置教程

原文:macOS下MySQL 8.0 安装与配置教程 一.前言 1.本教程主要内容 适用Homebrew安装MySQL MySQL 8.0 基础适用于配置 MySQL shell管理常用语法示例(用户.权限等) MySQL字符编码配置 MySQL远程访问配置 2.本教程环境信息与适用范围 环境信息 软件/环境 版本/说明 macOS macOS High Sierra MySQL MySQL 8.0.12 适用范围 软件 版本 macOS macOS MySQL 8.0.x 二.MySQL安装

MySQL数据库的安装和配置

MySQL数据库的安装和配置 1.数据库概念 ? 数据库就是保存数据的地方,在没有数据库之前,我们是这样保存数据的: ? 1.随意的存到了一个文件中 数据格式也是千差万别的 ? 2.软件开发目录规范 ? 规定了数据存放的位置 ps:数据都是保存在本地的 2.数据库如何保存数据的? ··将保存数据的部分 存到一个公共的地方 所有的用户涉及到数据相关 都必须来这个公共地方查找 3.数据库之MySQL ? 本质就是一款基于网络通信的应用软件 ? 任何基于网络通信的软件 底层都是socket ? 服务端

CentOS6.4下Mysql数据库的安装与配置,导入数据库,授权远程ip

卸载掉原有mysql 因为mysql数据库在Linux上实在是太流行了,所以目前下载的主流Linux系统版本基本上都集成了mysql数据库在里面,我们可以通过如下命令来查看我们的操作系统上是否已经安装了mysql数据库 [[email protected] ~]# rpm -qa | grep mysql // 这个命令就会查看该操作系统上是否已经安装了mysql数据库 有的话,我们就通过 rpm -e 命令 或者 rpm -e --nodeps 命令来卸载掉 [[email protected

第一章 Mysql简介及安装和配置

第一章 Mysql简介及安装和配置 ·    第一节:Mysql简介 MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下产品. 使用 C和 C++编写的. 集群(Cluster),适合大规模应用 ·   第二节:Mysql安装及配置 MySql安装注意一次行安装成功,不然要处理注册表. 安装选择编码格式为GBK或UTF-8. 安装MySql图形界面(Navica或MySQlog). p.MsoNormal,li.MsoNormal,div.Mso