Mysql高级——Mysql8一主一从,多主多从搭建

2023-11-04 04:20

本文主要是介绍Mysql高级——Mysql8一主一从,多主多从搭建,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

修改 /etc/hosts文件

ip地址 master1
ip地址 master2
ip地址 slave1
ip地址 slave2

一主一从

create database master1db;create table master1db.master1tab(name char(50));insert into master1db.master1tab VALUES(1111);insert into master1db.master1tab VALUES(2222);

master1 日志

[root@localhost opt]# vim /etc/my.cnf
[root@localhost opt]# cat /etc/my.cnf[mysqld]datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.socklog-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
log_bin
server-id=1
systemctl restart mysqld

创建用户

create user 'rep'@'192.168.18.%' identified by '123321zk';
grant replication slave,replication client on *.* to 'rep'@'192.168.18.%';alter user 'rep'@'192.168.18.%' identified with  mysql_native_password  by '123321zk';

master1上备份数据库

[root@localhost opt]# mysqldump -uroot -p'123321zk' --all-databases --single-transaction --master-data=2 --flush-logs > `date +%F`-mysql-all.sql[root@localhost opt]# ls
2023-10-12                                              mysql-community-common-8.0.25-1.el7.x86_64.rpm
2023-10-12-mysql-all.sql                                mysql-community-libs-8.0.25-1.el7.x86_64.rpm
mysql-community-client-8.0.25-1.el7.x86_64.rpm          mysql-community-server-8.0.25-1.el7.x86_64.rpm
mysql-community-client-plugins-8.0.25-1.el7.x86_64.rpm  rh

从机master2登录

[root@localhost opt]# mysql -urep -p'123321zk' -h master1;
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 8.0.25 MySQL Community Server - GPLCopyright (c) 2000, 2021, Oracle and/or its affiliates.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> 

修改master2的配置文件

[root@localhost opt]# vim /etc/my.cnf
[root@localhost opt]# cat /etc/my.cnf[mysqld]datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.socklog-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
server-id=2
systemctl restart mysqld

master2用root登录

[root@localhost opt]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.25 MySQL Community Server - GPLCopyright (c) 2000, 2021, Oracle and/or its affiliates.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> 

手动同步数据

复制master1的sql文件到matser2上

[root@localhost opt]# scp 2023-10-12-mysql-all.sql  master2:/opt
The authenticity of host 'master2 (192.168.18.131)' can't be established.
ECDSA key fingerprint is 83:bc:ac:37:44:8d:ea:4f:c7:c5:f7:2b:c5:0c:ee:b4.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'master2,192.168.18.131' (ECDSA) to the list of known hosts.
root@master2's password: 
2023-10-12-mysql-all.sql                                                                     100% 1190KB   1.2MB/s   00:00    
[root@localhost opt]# 

master2查看

[root@localhost opt]# ls
2023-10-12-mysql-all.sql                                mysql-community-common-8.0.25-1.el7.x86_64.rpm  rh
mysql-community-client-8.0.25-1.el7.x86_64.rpm          mysql-community-libs-8.0.25-1.el7.x86_64.rpm
mysql-community-client-plugins-8.0.25-1.el7.x86_64.rpm  mysql-community-server-8.0.25-1.el7.x86_64.rpm

master2上root用户执行

mysql> source /opt/2023-10-12-mysql-all.sql;
Query OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.00 sec)
.....# 查询成功!
mysql> select * from master1db.master1tab;
+------+
| name |
+------+
| 1111 |
| 2222 |
+------+
2 rows in set (0.00 sec)

配置日志偏移量

mysql> change master to master_host='master1',master_user='rep',master_password='123321zk',master_log_file='localhost-bin.000002',master_log_pos=156;
Query OK, 0 rows affected, 8 warnings (0.05 sec)

启动从机master2

mysql> start slave;
Query OK, 0 rows affected, 1 warning (0.00 sec)

master1查看偏移量

mysql> show master status;
+----------------------+----------+--------------+------------------+-------------------+
| File                 | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+----------------------+----------+--------------+------------------+-------------------+
| localhost-bin.000002 |      448 |              |                  |                   |
+----------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

master2更新偏移量

mysql> change master to master_host='master1',master_user='rep',master_password='123321zk',master_log_file='localhost-bin.000002',master_log_pos=448;
Query OK, 0 rows affected, 8 warnings (0.05 sec)mysql> start slave;
Query OK, 0 rows affected, 1 warning (0.12 sec)mysql> show slave status\G;
*************************** 1. row ***************************Slave_IO_State: Waiting for master to send eventMaster_Host: master1Master_User: repMaster_Port: 3306Connect_Retry: 60Master_Log_File: localhost-bin.000002Read_Master_Log_Pos: 448Relay_Log_File: localhost-relay-bin.000002Relay_Log_Pos: 328Relay_Master_Log_File: localhost-bin.000002Slave_IO_Running: YesSlave_SQL_Running: YesReplicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0Last_Error: Skip_Counter: 0Exec_Master_Log_Pos: 448Relay_Log_Space: 541Until_Condition: NoneUntil_Log_File: Until_Log_Pos: 0Master_SSL_Allowed: NoMaster_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: NoLast_IO_Errno: 0Last_IO_Error: Last_SQL_Errno: 0Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 1Master_UUID: d4996f86-68fd-11ee-ae55-000c29980ceaMaster_Info_File: mysql.slave_master_infoSQL_Delay: 0SQL_Remaining_Delay: NULLSlave_SQL_Running_State: Slave has read all relay log; waiting for more updatesMaster_Retry_Count: 86400Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0Replicate_Rewrite_DB: Channel_Name: Master_TLS_Version: Master_public_key_path: Get_master_public_key: 0Network_Namespace: 
1 row in set, 1 warning (0.00 sec)ERROR: 
No query specifiedmysql> 

双主双从

修改master1的配置文件

[root@localhost ~]# vim /etc/my.cnf[mysqld]datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.socklog-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pidlog-bin=/var/lib/mysql/binlog
server-id=1
# 跳过不备份数据库
binlog-ignore-db=mysql
binlog-ignore-db=information_schema
# 数据库
binlog-do-db=mydb2
# 日志格式
binlog_format=statement
# 过期时间
expire_logs_days=7
slave_skip_errors=1062
# 作为从数据库 写入操作也要更新二进制文件
log-slave-updates
# 标识自增长字段每次递增的量 就是步长
auto-increment-increment=2
# 表示自增从哪个数开始
auto-increment-offset=1

重启master1数据库

systemctl restart mysqld

修改master2配置文件

[root@localhost ~]# cat /etc/my.cnf[mysqld]datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.socklog-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pidlog-bin=/var/lib/mysql/binlog
server-id=3
# 跳过不备份数据库
binlog-ignore-db=mysql
binlog-ignore-db=information_schema
# 数据库
binlog-do-db=mydb2
# 日志格式
binlog_format=statement
# 过期时间
expire_logs_days=7
slave_skip_errors=1062
# 作为从数据库 写入操作也要更新二进制文件
log-slave-updates
# 标识自增长字段每次递增的量 就是步长
auto-increment-increment=2
# 表示自增从哪个数开始
auto-increment-offset=2
systemctl restart mysqld

更改slave1配置文件

[root@localhost ~]# cat /etc/my.cnf[mysqld]datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.socklog-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid# 服务id
server-id=2
# 启用中继日志
relay-log=mysql-relay

更改slave2配置文件

[mysqld]datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.socklog-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid# 服务id
server-id=4
# 启用中继日志
relay-log=mysql-relay

分别重启slave1和slave2

systemctl restart mysqld

master1,master2配置 创建用户并授权 两个主数据库都要创

mysql> CREATE USER 'repl_user'@'%' IDENTIFIED WITH mysql_native_password BY '123321zk';
Query OK, 0 rows affected (0.01 sec)mysql> CREATE USER 'slave_sync_user'@'%' IDENTIFIED WITH mysql_native_password BY '123321zk';
Query OK, 0 rows affected (0.00 sec)mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl_user'@'%';
Query OK, 0 rows affected (0.00 sec)mysql> GRANT REPLICATION SLAVE ON *.* TO 'slave_sync_user'@'%';
Query OK, 0 rows affected (0.01 sec)

在这里插入图片描述

主1从1

查看master1的偏移量

mysql> show master status;
+---------------+----------+--------------+--------------------------+-------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB         | Executed_Gtid_Set |
+---------------+----------+--------------+--------------------------+-------------------+
| binlog.000003 |     1198 | mydb2        | mysql,information_schema |                   |
+---------------+----------+--------------+--------------------------+-------------------+
1 row in set (0.00 sec)

修改slave1 配置主master1从关系

mysql> change master to master_host='master1',master_user='slave_sync_user',master_password='123321zk',master_log_file='binlog.000003',master_log_pos=1198;
Query OK, 0 rows affected, 8 warnings (0.51 sec)

启动slave1

mysql> start slave;
Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> show slave status\G;
*************************** 1. row ***************************Slave_IO_State: Waiting for master to send eventMaster_Host: master1Master_User: slave_sync_userMaster_Port: 3306Connect_Retry: 60Master_Log_File: binlog.000003Read_Master_Log_Pos: 1198Relay_Log_File: mysql-relay.000002Relay_Log_Pos: 321Relay_Master_Log_File: binlog.000003Slave_IO_Running: YesSlave_SQL_Running: YesReplicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0Last_Error: Skip_Counter: 0Exec_Master_Log_Pos: 1198Relay_Log_Space: 526Until_Condition: NoneUntil_Log_File: Until_Log_Pos: 0Master_SSL_Allowed: NoMaster_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: NoLast_IO_Errno: 0Last_IO_Error: Last_SQL_Errno: 0Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 1Master_UUID: d4996f86-68fd-11ee-ae55-000c29980ceaMaster_Info_File: mysql.slave_master_infoSQL_Delay: 0SQL_Remaining_Delay: NULLSlave_SQL_Running_State: Slave has read all relay log; waiting for more updatesMaster_Retry_Count: 86400Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0Replicate_Rewrite_DB: Channel_Name: Master_TLS_Version: Master_public_key_path: Get_master_public_key: 0Network_Namespace: 
1 row in set, 1 warning (0.00 sec)
主2从2

主2msql 作为主服务器

从2mysql作为从服务器

查看master2状态

mysql> show master status;
+---------------+----------+--------------+--------------------------+-------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB         | Executed_Gtid_Set |
+---------------+----------+--------------+--------------------------+-------------------+
| binlog.000002 |     1654 | mydb2        | mysql,information_schema |                   |
+---------------+----------+--------------+--------------------------+-------------------+
1 row in set (0.00 sec)

修改slave2 配置主master2从关系

mysql> change master to master_host='master2',master_user='slave_sync_user',master_password='123321zk',master_log_file='binlog.000002',master_log_pos=1654;
Query OK, 0 rows affected, 8 warnings (0.51 sec)

启动slave2

mysql> start slave;
Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> show slave status\G;
*************************** 1. row ***************************Slave_IO_State: Waiting for master to send eventMaster_Host: master2Master_User: slave_sync_userMaster_Port: 3306Connect_Retry: 60Master_Log_File: binlog.000002Read_Master_Log_Pos: 1654Relay_Log_File: mysql-relay.000002Relay_Log_Pos: 321Relay_Master_Log_File: binlog.000002Slave_IO_Running: YesSlave_SQL_Running: YesReplicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0Last_Error: Skip_Counter: 0Exec_Master_Log_Pos: 1654Relay_Log_Space: 526Until_Condition: NoneUntil_Log_File: Until_Log_Pos: 0Master_SSL_Allowed: NoMaster_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: NoLast_IO_Errno: 0Last_IO_Error: Last_SQL_Errno: 0Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 3Master_UUID: d5b21ed3-68fd-11ee-b692-000c29dadb21Master_Info_File: mysql.slave_master_infoSQL_Delay: 0SQL_Remaining_Delay: NULLSlave_SQL_Running_State: Slave has read all relay log; waiting for more updatesMaster_Retry_Count: 86400Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0Replicate_Rewrite_DB: Channel_Name: Master_TLS_Version: Master_public_key_path: Get_master_public_key: 0Network_Namespace: 
1 row in set, 1 warning (0.01 sec)
主1主2

修改master2 从master1

mysql> change master to master_host='master1',master_user='repl_user',master_password='123321zk',master_log_file='binlog.000003',master_log_pos=1198;
Query OK, 0 rows affected, 8 warnings (0.73 sec)mysql> start slave;
Query OK, 0 rows affected, 1 warning (0.02 sec)mysql> show slave status\G;
*************************** 1. row ***************************Slave_IO_State: Waiting for master to send eventMaster_Host: master1Master_User: repl_userMaster_Port: 3306Connect_Retry: 60Master_Log_File: binlog.000003Read_Master_Log_Pos: 1198Relay_Log_File: localhost-relay-bin.000002Relay_Log_Pos: 321Relay_Master_Log_File: binlog.000003Slave_IO_Running: YesSlave_SQL_Running: YesReplicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0Last_Error: Skip_Counter: 0Exec_Master_Log_Pos: 1198Relay_Log_Space: 534Until_Condition: NoneUntil_Log_File: Until_Log_Pos: 0Master_SSL_Allowed: NoMaster_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: NoLast_IO_Errno: 0Last_IO_Error: Last_SQL_Errno: 0Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 1Master_UUID: d4996f86-68fd-11ee-ae55-000c29980ceaMaster_Info_File: mysql.slave_master_infoSQL_Delay: 0SQL_Remaining_Delay: NULLSlave_SQL_Running_State: Slave has read all relay log; waiting for more updatesMaster_Retry_Count: 86400Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0Replicate_Rewrite_DB: Channel_Name: Master_TLS_Version: Master_public_key_path: Get_master_public_key: 0Network_Namespace: 
1 row in set, 1 warning (0.00 sec)
主2主1

修改master1 从master2

master2查看

mysql> show master status;
+---------------+----------+--------------+--------------------------+-------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB         | Executed_Gtid_Set |
+---------------+----------+--------------+--------------------------+-------------------+
| binlog.000002 |     1654 | mydb2        | mysql,information_schema |                   |
+---------------+----------+--------------+--------------------------+-------------------+
1 row in set (0.00 sec)

修改master1 从master2

mysql> change master to master_host='master2',master_user='repl_user',master_password='123321zk',master_log_file='binlog.000002',master_log_pos=1654;
Query OK, 0 rows affected, 8 warnings (0.12 sec)mysql> start slave;
Query OK, 0 rows affected, 1 warning (0.01 sec)mysql> show slave status\G;
*************************** 1. row ***************************Slave_IO_State: Waiting for master to send eventMaster_Host: master2Master_User: repl_userMaster_Port: 3306Connect_Retry: 60Master_Log_File: binlog.000002Read_Master_Log_Pos: 1654Relay_Log_File: localhost-relay-bin.000002Relay_Log_Pos: 321Relay_Master_Log_File: binlog.000002Slave_IO_Running: YesSlave_SQL_Running: YesReplicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0Last_Error: Skip_Counter: 0Exec_Master_Log_Pos: 1654Relay_Log_Space: 534Until_Condition: NoneUntil_Log_File: Until_Log_Pos: 0Master_SSL_Allowed: NoMaster_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: NoLast_IO_Errno: 0Last_IO_Error: Last_SQL_Errno: 0Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 3Master_UUID: d5b21ed3-68fd-11ee-b692-000c29dadb21Master_Info_File: mysql.slave_master_infoSQL_Delay: 0SQL_Remaining_Delay: NULLSlave_SQL_Running_State: Slave has read all relay log; waiting for more updatesMaster_Retry_Count: 86400Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0Replicate_Rewrite_DB: Channel_Name: Master_TLS_Version: Master_public_key_path: Get_master_public_key: 0Network_Namespace: 
1 row in set, 1 warning (0.00 sec)

在master1上创建数据库

CREATE DATABASE mydb2;
CREATE TABLE mydb2.books (
id INT PRIMARY KEY auto_increment,
name VARCHAR ( 50 ));
INSERT INTO mydb2.books ( NAME )
VALUES
( 'test mysql' );

查看其余数据库是否同步

全部同步成功

在这里插入图片描述

解决问题参考链接

主从同步报错Last_IO_Error: error connecting to master ‘use@192.XXXX‘ - retry-time: 60 retries: 86400解决办法。-CSDN博客

MySQL主从复制报错:Got fatal error 1236 from master when reading data from-CSDN博客

解决mysql8.0主从配置,从库连接报错:Authentication plugin ‘caching_sha2_password‘ reported error_authentication plugin’caching-CSDN博客

这篇关于Mysql高级——Mysql8一主一从,多主多从搭建的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/343181

相关文章

SQL表间关联查询实例详解

《SQL表间关联查询实例详解》本文主要讲解SQL语句中常用的表间关联查询方式,包括:左连接(leftjoin)、右连接(rightjoin)、全连接(fulljoin)、内连接(innerjoin)、... 目录简介样例准备左外连接右外连接全外连接内连接交叉连接自然连接简介本文主要讲解SQL语句中常用的表

SQL server配置管理器找不到如何打开它

《SQLserver配置管理器找不到如何打开它》最近遇到了SQLserver配置管理器打不开的问题,尝试在开始菜单栏搜SQLServerManager无果,于是将自己找到的方法总结分享给大家,对SQ... 目录方法一:桌面图标进入方法二:运行窗口进入方法三:查找文件路径方法四:检查 SQL Server 安

MySQL 中的 LIMIT 语句及基本用法

《MySQL中的LIMIT语句及基本用法》LIMIT语句用于限制查询返回的行数,常用于分页查询或取部分数据,提高查询效率,:本文主要介绍MySQL中的LIMIT语句,需要的朋友可以参考下... 目录mysql 中的 LIMIT 语句1. LIMIT 语法2. LIMIT 基本用法(1) 获取前 N 行数据(

MySQL 分区与分库分表策略应用小结

《MySQL分区与分库分表策略应用小结》在大数据量、复杂查询和高并发的应用场景下,单一数据库往往难以满足性能和扩展性的要求,本文将详细介绍这两种策略的基本概念、实现方法及优缺点,并通过实际案例展示如... 目录mysql 分区与分库分表策略1. 数据库水平拆分的背景2. MySQL 分区策略2.1 分区概念

MySQL高级查询之JOIN、子查询、窗口函数实际案例

《MySQL高级查询之JOIN、子查询、窗口函数实际案例》:本文主要介绍MySQL高级查询之JOIN、子查询、窗口函数实际案例的相关资料,JOIN用于多表关联查询,子查询用于数据筛选和过滤,窗口函... 目录前言1. JOIN(连接查询)1.1 内连接(INNER JOIN)1.2 左连接(LEFT JOI

MySQL 中查询 VARCHAR 类型 JSON 数据的问题记录

《MySQL中查询VARCHAR类型JSON数据的问题记录》在数据库设计中,有时我们会将JSON数据存储在VARCHAR或TEXT类型字段中,本文将详细介绍如何在MySQL中有效查询存储为V... 目录一、问题背景二、mysql jsON 函数2.1 常用 JSON 函数三、查询示例3.1 基本查询3.2

MySQL中动态生成SQL语句去掉所有字段的空格的操作方法

《MySQL中动态生成SQL语句去掉所有字段的空格的操作方法》在数据库管理过程中,我们常常会遇到需要对表中字段进行清洗和整理的情况,本文将详细介绍如何在MySQL中动态生成SQL语句来去掉所有字段的空... 目录在mysql中动态生成SQL语句去掉所有字段的空格准备工作原理分析动态生成SQL语句在MySQL

MySQL中FIND_IN_SET函数与INSTR函数用法解析

《MySQL中FIND_IN_SET函数与INSTR函数用法解析》:本文主要介绍MySQL中FIND_IN_SET函数与INSTR函数用法解析,本文通过实例代码给大家介绍的非常详细,感兴趣的朋友一... 目录一、功能定义与语法1、FIND_IN_SET函数2、INSTR函数二、本质区别对比三、实际场景案例分

MySQL中的交叉连接、自然连接和内连接查询详解

《MySQL中的交叉连接、自然连接和内连接查询详解》:本文主要介绍MySQL中的交叉连接、自然连接和内连接查询,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、引入二、交php叉连接(cross join)三、自然连接(naturalandroid join)四

Mysql如何将数据按照年月分组的统计

《Mysql如何将数据按照年月分组的统计》:本文主要介绍Mysql如何将数据按照年月分组的统计方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录mysql将数据按照年月分组的统计要的效果方案总结Mysql将数据按照年月分组的统计要的效果方案① 使用 DA