mysql 主从设置
准备工作: master机和slave机的相关配置 1、修改master机器中mysql配置文件my.cnf,该文件在/etc目录下 在[mysqld]配置段添加如下字段 server-id=1 log-bin=log binlog-do-db=repl //需要同步的数据库,如果没有本行,即表示同步所有的数据库 此参数可以重复
准备工作:master机和slave机的相关配置
1、修改master机器中mysql配置文件my.cnf,该文件在/etc目录下
在[mysqld]配置段添加如下字段
server-id=1
log-bin=log
binlog-do-db=repl //需要同步的数据库,如果没有本行,即表示同步所有的数据库 此参数可以重复设置,此参数 可能会出现问题,尽量不用,过滤数据 设置到从库
binlog-ignore-db=mysql //被忽略的数据库 同上 最好不用 过滤设置到从库
修改slave机中mysql配置文件
同样在[mysqld]字段下添加如下内容
server-id=2
master-host=192.168.1.222
master-user=repl
master-password=123456
master-port=3306
master-connect-retry=60
# replicate-ignore-db=mysql 忽略的数据库 同上
# master-connect-retry=60 如果从服务器发现主服务器断掉,重新连接的时间差(秒)
#replicate-do-db=repl //同步的数据库(需要备份的数据库名),不写本行 表示 同步所有数据库
#建议用下面两个参数
replicate-wild-do-table=db_name.%
replicate-wild-ignore-table=mysql.%
然后重启slave机的mysql
-------------------------------------------------------------------------------------------------
1、登录mysql 首先 查看 数据库的版本
>select version();
2、检查主库 和 从库的 server_id
>show global variables like 'server_id';
3、查看主库的二进制文件是否开启
>show global variables like 'log_bin';
若没有开启,那么需要重启数据库的:
(1)在my.cnf参数文件中[mysqld]中添加
log-bin = mysql-bin
(2)重启MySQL数据库。
4、检查到从库的网络及端口是否可达
#netstat -tnlp|grep mysqld
#telnet 192.168.230.71 3306
5、在主库创建同步帐号并授权 replication
>create user 'repl'@'host' identified by 'password';
>grant replication slave,replication client on *.* to 'repl'@'host';
6、再从库中测试是否可以使用repl用户登录
#mysql -urepl -ppassword -hhost -P3306
7、记录主库master上当前二进制日志名和偏移量
主要是用于slave中指定开始恢复的位置。
>show master status\G
8、备份数据库
启动主从复制功能
slave start;
查看主从信息
show slave status\G;
如果打印的信息中slave_IO_Running:yes和Slave_SQL_Runnning:yes 则表示配置成功

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Big data structure processing skills: Chunking: Break down the data set and process it in chunks to reduce memory consumption. Generator: Generate data items one by one without loading the entire data set, suitable for unlimited data sets. Streaming: Read files or query results line by line, suitable for large files or remote data. External storage: For very large data sets, store the data in a database or NoSQL.

MySQL query performance can be optimized by building indexes that reduce lookup time from linear complexity to logarithmic complexity. Use PreparedStatements to prevent SQL injection and improve query performance. Limit query results and reduce the amount of data processed by the server. Optimize join queries, including using appropriate join types, creating indexes, and considering using subqueries. Analyze queries to identify bottlenecks; use caching to reduce database load; optimize PHP code to minimize overhead.

Backing up and restoring a MySQL database in PHP can be achieved by following these steps: Back up the database: Use the mysqldump command to dump the database into a SQL file. Restore database: Use the mysql command to restore the database from SQL files.

How to insert data into MySQL table? Connect to the database: Use mysqli to establish a connection to the database. Prepare the SQL query: Write an INSERT statement to specify the columns and values to be inserted. Execute query: Use the query() method to execute the insertion query. If successful, a confirmation message will be output.

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the "MySQL Native Password" plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

To use MySQL stored procedures in PHP: Use PDO or the MySQLi extension to connect to a MySQL database. Prepare the statement to call the stored procedure. Execute the stored procedure. Process the result set (if the stored procedure returns results). Close the database connection.

Creating a MySQL table using PHP requires the following steps: Connect to the database. Create the database if it does not exist. Select a database. Create table. Execute the query. Close the connection.

Oracle database and MySQL are both databases based on the relational model, but Oracle is superior in terms of compatibility, scalability, data types and security; while MySQL focuses on speed and flexibility and is more suitable for small to medium-sized data sets. . ① Oracle provides a wide range of data types, ② provides advanced security features, ③ is suitable for enterprise-level applications; ① MySQL supports NoSQL data types, ② has fewer security measures, and ③ is suitable for small to medium-sized applications.
