Home Database Mysql Tutorial 小记一次mysql主从配置解决方案_MySQL

小记一次mysql主从配置解决方案_MySQL

May 30, 2016 pm 05:10 PM
mysql

  今天研究了个开源项目,数据库是mysql的,其中的脚本数据需要备份,由于本人的机器时mac pro,而且mac下的数据库连接工具都不怎么好用,就想着如何利用windows下的数据库连接工具使用,并做相关备份,另外windows系统下的sqlyog工具还是非常强大的,在此推荐。

  因此为了使用sqlyog等windows系统下的连接工具,便开始了一天的折腾。

  首先两种思路,其一是利用另外一台宏碁笔记本电脑,直接在其上安装sqlyog使用,通过无线局域网进行连接使用,这种方式太过麻烦,而且来回换电脑很麻烦,远程连接使用也很慢。其二是安装虚拟机,在虚拟机上安装连接工具。

  由于本人的mac pro已经安装mysql数据库,并且已经安装了virtualbox虚拟机并安装了windows7系统,并在windows7系统中也安装了mysql。

  1.在虚拟机win7系统中安装sqlyog,直接连接mac系统的mysql,并导出备份,这个很简单。(当然要注意虚拟机与mac机器的网络连接是通的)

    1)首先要设置虚拟机网卡设置,选择桥接模式,virtualbox这类虚拟机的桥接模式的概念是虚拟机作为网络中的一台单独的机器,有自己的ip,与局域网中的ip是想通的,

      设置virtualbox的桥接模式如图所示

     !

      

这样按照图中的设置,虚拟机根主机就可以相互访问了。

  2)利用sqlyog进行连接

  

对了 还有一点需要注意的是,由于局域网ip可能不会固定,正好本人用的是小米路由器,有绑定设备ip的功能,这样ip就固定啦

从上面的图中可以看出,主机ip跟虚拟机ip是独立的啦。

2.mysql主从备份的方式,mac pro为主master,虚拟机为从slave

1)首先由于mac电脑mysql客户端安装完成后,默认是没有my.cnf文件的,即使修改了/usr/local/mysql/的相关配置也是没有用的,这就需要自定义mysql配置了,将/usr/local/mysql/support-files/中的my-default.cnf 文件 拷贝到/etc目录下,当然这里也遇见问题了,服务启动不了了

这就需要在配置文件中加入explicit_defaults_for_timestamp=true

2)修改配置文件,如下所示

3)修改虚拟机中的mysql目录中的my.cnf

修改mysqld节点

4)重启master及slave并查看状态

查看master状态

查看slave状态

当看到上面两张图片的时候则证明配置成功,当然本人并没有那么顺利,中途遇到了很多问题

其一:Got fatal error 1236 from master when reading data from binary log
这中问题按照网上大部分的解决方法是,首先查看master的状态,并记录下相关信息
比如信息为:


要记录下file:mysql-bin.000002 position:16093
并在slave中执行:

这种方式应该是没有问题的。如果上面这种方式不行,可以试试下面这种,本人试了试应该是没问题,

(这种方式本人可以可能是因为本人配置的时候没有按照规范来,导致主从不一致的原因)

其二:Slave can not handle replication events with the checksum that master is configured to log
  这个错误一般出现在master5.6,slave在低版本的情况下。这是由于5.6使用了crc32做binlog的checksum。除了把master的设置从crc32改到none
  binlog-checksum = none [my.cnf]

其三:本人今天花费了大量的时间主要原因便是这点了,本人在虚拟机里查看slave状态显示都正确,

但是本人通过虚拟机的连接工具,将master数据库中添加了一张表并插入数据,但是总是没有同步到从mysql,于是查看进程
从mysql进程

master进程

这点问题也就是纠结了一天的问题,当然也没有找出具体原因,看提示原因貌似是什么进程已经睡眠的原因,但是为啥睡眠没搞明白,查看slave hosts也没有查到

当然最后,没办法了,纠结了很久也没有发现什么原因的情况下,本人直接在mac机器上直接通过终端插入数据,居然成功了。。。无语。。不过最终能够同步了至少还有点欣慰。至于什么出现这个问题要找时间好好查找原因了。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1269
29
C# Tutorial
1248
24
MySQL's Role: Databases in Web Applications MySQL's Role: Databases in Web Applications Apr 17, 2025 am 12:23 AM

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

Laravel Introduction Example Laravel Introduction Example Apr 18, 2025 pm 12:45 PM

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

MySQL and phpMyAdmin: Core Features and Functions MySQL and phpMyAdmin: Core Features and Functions Apr 22, 2025 am 12:12 AM

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

MySQL vs. Other Programming Languages: A Comparison MySQL vs. Other Programming Languages: A Comparison Apr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Solve database connection problem: a practical case of using minii/db library Solve database connection problem: a practical case of using minii/db library Apr 18, 2025 am 07:09 AM

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

Laravel framework installation method Laravel framework installation method Apr 18, 2025 pm 12:54 PM

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

MySQL for Beginners: Getting Started with Database Management MySQL for Beginners: Getting Started with Database Management Apr 18, 2025 am 12:10 AM

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

Solve MySQL mode problem: The experience of using the TheliaMySQLModesChecker module Solve MySQL mode problem: The experience of using the TheliaMySQLModesChecker module Apr 18, 2025 am 08:42 AM

When developing an e-commerce website using Thelia, I encountered a tricky problem: MySQL mode is not set properly, causing some features to not function properly. After some exploration, I found a module called TheliaMySQLModesChecker, which is able to automatically fix the MySQL pattern required by Thelia, completely solving my troubles.

See all articles