Bug #112364 Create table like doesn't write the charset on binlog if its created from a temp
Submitted: 15 Sep 2023 21:40 Modified: 20 Sep 2023 19:51
Reporter: Roberto de Bem Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Replication Severity:S3 (Non-critical)
Version:8.0.34 OS:Any
Assigned to: CPU Architecture:Any
Tags: CREATE TABLE LIKE, temporary table

[15 Sep 2023 21:40] Roberto de Bem
Description:
When creating a table with CREATE TABLE ... LIKE ... from a temporary table, the create table isn't written entirely on the binary log, causing an error on the replica, which will create the table with the charset from the default database.

Column 1 of table 'test.joinit2' cannot be converted from type 'varchar(64(bytes))' to type 'varchar(256(bytes) utf8mb4)', Error_code: MY-013146

Doesn't happen with persistent tables.

How to repeat:
Create a temporary table:

MySQL > CREATE TEMPORARY TABLE `joinit` (`i` int(11) NOT NULL AUTO_INCREMENT,`s` varchar(64) DEFAULT NULL,`t` time NOT NULL,`g` int(11) NOT NULL,PRIMARY KEY (`i`) ) ENGINE=InnoDB  DEFAULT CHARSET=latin1;
Query OK, 0 rows affected, 2 warnings (0.01 sec)

Create a persistent table from joinit:

MySQL > CREATE TABLE joinit2 LIKE joinit;

Check binlog:

# at 9873
#230915 21:16:47 server id 42442  end_log_pos 10123 CRC32 0x1998ae04    Query   thread_id=15    exec_time=0     error_code=0    Xid = 103
use `test2`/*!*/;
SET TIMESTAMP=1694812607/*!*/;
SET @@session.pseudo_thread_id=15/*!*/;
/*!80013 SET @@session.sql_require_primary_key=0*//*!*/;
CREATE TABLE `joinit2` (
  `i` int NOT NULL AUTO_INCREMENT,
  `s` varchar(64) DEFAULT NULL,
  `t` time NOT NULL,
  `g` int NOT NULL,
  PRIMARY KEY (`i`)
) ENGINE=InnoDB <------ without the charset 
/*!*/;
SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/;
DELIMITER ;
# End of log file

Suggested fix:
Write the charset(CHARSET=XXX) on the binary log to ensure that the tables will be equal if the use of the binlog is needed.
[20 Sep 2023 19:51] MySQL Verification Team
Thank you for your report, I managed to reproduce the problem