【Mysql】字符集引發的主從報錯
收到報警,主從斷了
mysql> show global variables like '%character%';
+--------------------------+-----------------------------------------+
| Variable_name | Value |
+--------------------------+-----------------------------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| character_sets_dir | /usr/local/mysql-5.6.34/share/charsets/ |
+--------------------------+-----------------------------------------+
是一樣的
關於字符集的核心月報:
1.檢視主從的字符集設定
-
mysql> show global variables like '%character%';
+--------------------------+-----------------------------------------+
| Variable_name | Value |
+--------------------------+-----------------------------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| character_sets_dir | /usr/local/mysql-5.6.34/share/charsets/ |
+--------------------------+-----------------------------------------+
mysql> show global variables like '%character%';
+--------------------------+-----------------------------------------+
| Variable_name | Value |
+--------------------------+-----------------------------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| character_sets_dir | /usr/local/mysql-5.6.34/share/charsets/ |
+--------------------------+-----------------------------------------+
是一樣的
2. 檢視報錯表的字符集
- 主:
-
CREATE TABLE `svc_special_important_step_setting` (
PRIMARY KEY (`svc_special_important_step_setting_id`),
KEY `idx_CityId` (`city_id`),
KEY `idx_CompanyId` (`company_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='安檢關鍵環節設定'; -
-
- 從:
-
-
CREATE TABLE `svc_special_important_step_setting` (
PRIMARY KEY (`svc_special_important_step_setting_id`),
KEY `idx_CityId` (`city_id`),
KEY `idx_CompanyId` (`company_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='安檢關鍵環節設定';
為什麼表的字符集會不一樣呢? -
CREATE TABLE `svc_special_important_step_setting` (
3.檢視了下庫的字符集
-
mysql> show create database xxxxxx;
-
+-------------+-------------------------------------------------------------------------+
-
| Database | Create Database |
-
+-------------+-------------------------------------------------------------------------+
-
| ecejservice | CREATE DATABASE `xxxxx` /*!40100 DEFAULT CHARACTER SET utf8 */ |
-
+-------------+-------------------------------------------------------------------------+
-
1 row in set (0.00 sec)
-
-
mysql> show create database xxxxxx;
-
+-------------+-------------------------------------------------------------------------+
-
| Database | Create Database |
-
+-------------+-------------------------------------------------------------------------+
-
| ecejservice | CREATE DATABASE `xxxxxx` /*!40100 DEFAULT CHARACTER SET utf8mb4 */ |
- +-------------+-------------------------------------------------------------------------+
主從兩個庫的字符集都不一樣,原因要追溯到歷史原因了,兩個庫的來源不一樣,一個來之與xtracebackup 一個來源於mysqldump, 並且來源庫的字符集就是不一樣的
一個case
- master:
-
mysql> show create database test1234\G
*************************** 1. row ***************************
Database: test1234
Create Database: CREATE DATABASE `test1234` /*!40100 DEFAULT CHARACTER SET utf8mb4 */
1 row in set (0.00 sec)
-
- slave:
-
mysql> show create database test1234\G
*************************** 1. row ***************************
Database: test1234
Create Database: CREATE DATABASE `test1234` /*!40100 DEFAULT CHARACTER SET utf8 */
1 row in set (0.00 sec)
master:建表
CREATE TABLE `test` (
`id` int(11) DEFAULT NULL,
`tname` varchar(20) DEFAULT NULL
) ENGINE=InnoDB
檢視主從表的資訊:
master:
mysql> show create table test\G
*************************** 1. row ***************************
Table: test
Create Table: CREATE TABLE `test` (
`id` int(11) DEFAULT NULL,
`tname` varchar(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
slave:
mysql> show create table test\G
*************************** 1. row ***************************
Table: test
Create Table: CREATE TABLE `test` (
`id` int(11) DEFAULT NULL,
`tname` varchar(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
可以看到:如果建表時不指定字符集會預設以當前database的字符集為準
master:插入資料
mysql> insert into test(id ,tname) values (123,'12314');
檢視主從狀態:
Replicate_Wild_Ignore_Table:
Last_Errno: 1677
Last_Error: Column 1 of table 'test1234.test' cannot be converted from type 'varchar(80)' to type 'varchar(20)'
Skip_Counter: 0
Exec_Master_Log_Pos: 158988157
Relay_Log_Space: 2240633
CREATE TABLE `test` (
`id` int(11) DEFAULT NULL,
`tname` varchar(20) DEFAULT NULL
) ENGINE=InnoDB
檢視主從表的資訊:
master:
mysql> show create table test\G
*************************** 1. row ***************************
Table: test
Create Table: CREATE TABLE `test` (
`id` int(11) DEFAULT NULL,
`tname` varchar(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
slave:
mysql> show create table test\G
*************************** 1. row ***************************
Table: test
Create Table: CREATE TABLE `test` (
`id` int(11) DEFAULT NULL,
`tname` varchar(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
可以看到:如果建表時不指定字符集會預設以當前database的字符集為準
master:插入資料
mysql> insert into test(id ,tname) values (123,'12314');
檢視主從狀態:
Replicate_Wild_Ignore_Table:
Last_Errno: 1677
Last_Error: Column 1 of table 'test1234.test' cannot be converted from type 'varchar(80)' to type 'varchar(20)'
Skip_Counter: 0
Exec_Master_Log_Pos: 158988157
Relay_Log_Space: 2240633
解決:修改庫的預設字符集吧
mysql> alter database xxxxxx DEFAULT CHARACTER SET utf8mb4;關於字符集的核心月報:
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29096438/viewspace-2146363/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- mysql主從跳過錯誤MySql
- 故障分析 | MySQL 從機故障重啟後主從同步報錯案例分析MySql主從同步
- mysql主從不同步報錯Last_Errno 1197MySqlAST
- mysql5.6主從引數詳解MySql
- mysql 主從錯誤以及監控MySql
- mysql memory引擎引起的主從 1032 錯誤MySql
- 【mysql】mysql的資料庫主從(一主一從)MySql資料庫
- MySQL主從同步報error 1236MySql主從同步Error
- Mysql 字符集引數翻譯MySql
- MySQL主從複製結構中常用引數MySql
- MySQL的主從複製與MySQL的主主複製MySql
- MySQL 主從複製錯誤1837MySql
- mysql主從和觸發器的關係MySql觸發器
- MySQL主從MySql
- MySQL 中一個雙引號的錯位引發的血案MySql
- 堆疊溢位報錯引發的思考
- 故障分析 | MySQL convert 函式導致的字符集報錯處理MySql函式
- vmware虛擬機器centos7上的MySQL主從報錯解決一例虛擬機CentOSMySql
- MySQL的主從複製MySql
- MySQL主從複製錯誤——列型別轉換錯誤MySql型別
- MySQL主從同步(一主一從、一主多從、主從從)等結構的概述與配置MySql主從同步
- MySQL 主從配置-之-一主一從MySql
- mysql主從配置MySql
- mysql 主從配置MySql
- mysql配置主從MySql
- mysql主從同步MySql主從同步
- mysql主從搭建MySql
- mysql主從和主備的區別MySql
- MySQL主從複製配置引數 -- logs-slave-updatesMySql
- MySQL(14)---Docker搭建MySQL主從複製(一主一從)MySqlDocker
- 【MySQL】一次擴充套件平臺引發的字符集調整薦MySql套件
- mysql主從複製(一):一主多從MySql
- MySQL 5.7的安裝及主從複製(主從同步)MySql主從同步
- mysql主從配置(清晰的思路)MySql
- MYSQL主從複製的搭建MySql
- 主從故障處理--session 級別引數複製錯誤Session
- MySQL主從同步報Client requested master to start replication from positionMySql主從同步clientAST
- 事故現場:MySQL 中一個雙引號的錯位引發的血案MySql