search
HomeDatabaseMysql Tutorial小记一次mysql主从配置解决方案_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
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
MySQL String Types: Storage, Performance, and Best PracticesMySQL String Types: Storage, Performance, and Best PracticesMay 10, 2025 am 12:02 AM

MySQLstringtypesimpactstorageandperformanceasfollows:1)CHARisfixed-length,alwaysusingthesamestoragespace,whichcanbefasterbutlessspace-efficient.2)VARCHARisvariable-length,morespace-efficientbutpotentiallyslower.3)TEXTisforlargetext,storedoutsiderows,

Understanding MySQL String Types: VARCHAR, TEXT, CHAR, and MoreUnderstanding MySQL String Types: VARCHAR, TEXT, CHAR, and MoreMay 10, 2025 am 12:02 AM

MySQLstringtypesincludeVARCHAR,TEXT,CHAR,ENUM,andSET.1)VARCHARisversatileforvariable-lengthstringsuptoaspecifiedlimit.2)TEXTisidealforlargetextstoragewithoutadefinedlength.3)CHARisfixed-length,suitableforconsistentdatalikecodes.4)ENUMenforcesdatainte

What are the String Data Types in MySQL?What are the String Data Types in MySQL?May 10, 2025 am 12:01 AM

MySQLoffersvariousstringdatatypes:1)CHARforfixed-lengthstrings,2)VARCHARforvariable-lengthtext,3)BINARYandVARBINARYforbinarydata,4)BLOBandTEXTforlargedata,and5)ENUMandSETforcontrolledinput.Eachtypehasspecificusesandperformancecharacteristics,sochoose

How to Grant Permissions to New MySQL UsersHow to Grant Permissions to New MySQL UsersMay 09, 2025 am 12:16 AM

TograntpermissionstonewMySQLusers,followthesesteps:1)AccessMySQLasauserwithsufficientprivileges,2)CreateanewuserwiththeCREATEUSERcommand,3)UsetheGRANTcommandtospecifypermissionslikeSELECT,INSERT,UPDATE,orALLPRIVILEGESonspecificdatabasesortables,and4)

How to Add Users in MySQL: A Step-by-Step GuideHow to Add Users in MySQL: A Step-by-Step GuideMay 09, 2025 am 12:14 AM

ToaddusersinMySQLeffectivelyandsecurely,followthesesteps:1)UsetheCREATEUSERstatementtoaddanewuser,specifyingthehostandastrongpassword.2)GrantnecessaryprivilegesusingtheGRANTstatement,adheringtotheprincipleofleastprivilege.3)Implementsecuritymeasuresl

MySQL: Adding a new user with complex permissionsMySQL: Adding a new user with complex permissionsMay 09, 2025 am 12:09 AM

ToaddanewuserwithcomplexpermissionsinMySQL,followthesesteps:1)CreatetheuserwithCREATEUSER'newuser'@'localhost'IDENTIFIEDBY'password';.2)Grantreadaccesstoalltablesin'mydatabase'withGRANTSELECTONmydatabase.TO'newuser'@'localhost';.3)Grantwriteaccessto'

MySQL: String Data Types and CollationsMySQL: String Data Types and CollationsMay 09, 2025 am 12:08 AM

The string data types in MySQL include CHAR, VARCHAR, BINARY, VARBINARY, BLOB, and TEXT. The collations determine the comparison and sorting of strings. 1.CHAR is suitable for fixed-length strings, VARCHAR is suitable for variable-length strings. 2.BINARY and VARBINARY are used for binary data, and BLOB and TEXT are used for large object data. 3. Sorting rules such as utf8mb4_unicode_ci ignores upper and lower case and is suitable for user names; utf8mb4_bin is case sensitive and is suitable for fields that require precise comparison.

MySQL: What length should I use for VARCHARs?MySQL: What length should I use for VARCHARs?May 09, 2025 am 12:06 AM

The best MySQLVARCHAR column length selection should be based on data analysis, consider future growth, evaluate performance impacts, and character set requirements. 1) Analyze the data to determine typical lengths; 2) Reserve future expansion space; 3) Pay attention to the impact of large lengths on performance; 4) Consider the impact of character sets on storage. Through these steps, the efficiency and scalability of the database can be optimized.

See all articles

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 Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool