前提,两台安装了同样版本mysql的服务器(其实好像版本不一样也行,但是稳妥起见,还是用一样版本的mysql吧,毕竟俺是个小白)。 主服务器ip:192.168.2.19从服务器ip:192.168.2.155 停止前端nginx服务,既停止php向mysql发起请求 一.给主服务器上创建一个
前提,两台安装了同样版本mysql的服务器(其实好像版本不一样也行,但是稳妥起见,还是用一样版本的mysql吧,毕竟俺是个小白)。
主服务器ip:192.168.2.19 从服务器ip:192.168.2.155
停止前端nginx服务,既停止php向mysql发起请求
一.给主服务器上创建一个用户用于给从服务器同步使用:
grant all privileges on *.* to slaveuser@丛库IP identified by '密码';
二.停止这两台服务器上的mysql服务:
/usr/local/mysql/bin/mysqladmin shutdown --socket=/opt/db/mysql/mysql.sock -uroot -ppassword
三.修改主服务器的配置文件
server-id = 1 #主机标示,整数
log_bin = /opt/db/mysql/data/mysql-bin.log #确保此文件可写
read-only = 0 #主机,读写都可以
binlog-do-db = test #需要备份数据,多个写多行
binlog-do-db = anotherdb #需要备份数据,多个写多行
四.在从服务器上拉取主服务器中的要同步的库的表结构和数据(需要输入主服务器的root密码)
scp -r -p root@192.168.2.19:/opt/db/mysql/data/fb_cn /opt/db/mysql/data/
并且改变/opt/db/mysql/data/中fb_cn的用户和用户组
五.启动主服务器mysql服务(根据自己具体情况启动)
/usr/local/mysql/bin/mysqld_safe
--defaults-file=/opt/db/mysql/my.cnf #mysql配置文件位置
--basedir=/usr/local/mysql #mysql安装目录
--pid-file=/opt/db/mysql/mysql.pid #pid文件创建位置
--datadir=/opt/db/mysql/data #数据文件位置
--socket=/opt/db/mysql/mysql.sock #sock文件位置
--log-error=/opt/db/mysql/err.log #错误日志文件位置
--log-slow-queries=/opt/db/mysql/slowquery.log& #慢查询日志文件位置
六.查看主服务器mysql状态,记录file和position,很重要,在从库设置中将被用到,此时需保证主服务器mysql不会有写操作
/usr/local/mysql/bin/mysql -uroot --socket=/opt/db/mysql/mysql.sock -p (进入mysql环境)
>show master status;
+——————+———-+————–+——————+
|File|Position|Binlog_Do_DB|Binlog_Ignore_DB|
+——————+———-+————–+——————+
|mysql-bin.000001|106| myslave | mysql
|+——————+———-+————–+——————+
七.修改从服务器的配置文件
server-id = 2 #主机标示,整数
log_bin = /opt/db/mysql/data/mysql-bin.log #binlog
master-host = 192.168.2.19 #主服务器ip地址
master-user = slaveuser #主服务器用于主从设置的用户
master-pass = 密码 #主服务器用于主从设置的用户密码
master-port = 3306 #主服务器端口号
master-connect-retry = 60 #从服务器发现主服务器断掉,重新连接时间(秒)
replicate-do-db = test #要进行主从同步的库名,用逗号隔开
replicate-do-db = another #要进行主从同步的库名,用逗号隔开
八.启动从服务器(根据自己具体情况启动)
/usr/local/mysql/bin/mysqld_safe
--defaults-file=/opt/db/mysql/my.cnf #mysql配置文件位置
--basedir=/usr/local/mysql #mysql安装目录
--pid-file=/opt/db/mysql/mysql.pid #pid文件创建位置
--datadir=/opt/db/mysql/data #数据文件位置
--socket=/opt/db/mysql/mysql.sock #sock文件位置
--log-error=/opt/db/mysql/err.log #错误日志文件位置
--log-slow-queries=/opt/db/mysql/slowquery.log& #慢查询日志文件位置
九.进入从服务器mysql环境中,配置Slave信息
/usr/local/mysql/bin/mysql -uroot --socket=/opt/db/mysql/mysql.sock -p
>CHANGE MASTER TO
>MASTER_HOST='192.168.2.19', #主服务器ip
>MASTER_PORT=3306, #主服务器mysql服务端口
>MASTER_USER='slaveuser', #主服务器中用于主从连接的用户名
>MASTER_PASSWORD='密码', #主服务器中用于主从连接的用户密码
>MASTER_LOG_FILE='mysql-bin.000001', #从主服务器的master状态中读取的file
>MASTER_LOG_POS=106; #从主服务器的master状态中读取的position
十.启动Slave服务
>start slave;
十一.查看从服务器状态
>show slave status\G;
如果发现
Waitingfor master to send event
Slave_IO_Running:Yes
Slave_SQL_Running:Yes
总体来说,这个配置还是很成功的,但是由于操作问题,在配置过程中,大脑缺弦了,直接把replicate-do-db = another这个考到了从服务器的mysql配置文件里,典型脑残啊,特此纪念一把,多花了一个小时的时间。

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

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.

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

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


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SublimeText3 Linux new version
SublimeText3 Linux latest version

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.