Bug #90348 mysqldump command line for exporting a table recreate table as latin1 collation
Submitted: 9 Apr 2018 10:33 Modified: 9 Apr 2018 12:38
Reporter: Hussam Shaheen Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server: mysqldump Command-line Client Severity:S2 (Serious)
Version:14.14 OS:Ubuntu (16)
Assigned to: CPU Architecture:Any

[9 Apr 2018 10:33] Hussam Shaheen
Description:
The mysqldump command recreates the table with a collation of latin1 although the original collation before dumping was utf8 - utf8_unicode_ci

How to repeat:
Create a table with a collation of utf8 - utf8_unicode_ci then run 
mysqldump -p – –user=username dbname tableName > tableName.sql
to export it and view the generated script and you will notice that the scripts recreate the table with a collation of latin1

Suggested fix:
Keep the original collation as it is.
[9 Apr 2018 12:17] MySQL Verification Team
Which server version are you using?

Server version: 5.7.23 Source distribution 2018-APR-04

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

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 5.7 > CREATE DATABASE colla;
Query OK, 1 row affected (0,00 sec)

mysql 5.7 > USE colla
Database changed
mysql 5.7 > CREATE TABLE userdb_entities (
    -> id INTEGER NOT NULL AUTO_INCREMENT,
    -> dn VARCHAR(100) NOT NULL UNIQUE,
    -> type ENUM('person', 'group') NOT NULL,
    -> created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    -> PRIMARY KEY (id)
    -> ) Engine=InnoDB, CHARACTER SET utf8 COLLATE utf8_unicode_ci;
Query OK, 0 rows affected (0,38 sec)

mysql 5.7 > exit
Bye
miguel@tikal:~/dbs $ 5.7/bin/mysqldump -uroot -p --socket=/tmp/mysql57.sock colla
Enter password:
-- MySQL dump 10.13  Distrib 5.7.23, for Linux (x86_64)
--
-- Host: localhost    Database: colla
-- ------------------------------------------------------
-- Server version       5.7.23

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `userdb_entities`
--

DROP TABLE IF EXISTS `userdb_entities`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `userdb_entities` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `dn` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
  `type` enum('person','group') COLLATE utf8_unicode_ci NOT NULL,
  `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `dn` (`dn`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `userdb_entities`
--

LOCK TABLES `userdb_entities` WRITE;
/*!40000 ALTER TABLE `userdb_entities` DISABLE KEYS */;
/*!40000 ALTER TABLE `userdb_entities` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2018-04-09  9:15:40
[9 Apr 2018 12:28] Hussam Shaheen
Server Version :

mysql  Ver 14.14 Distrib 5.6.33, for debian-linux-gnu (x86_64) using  EditLine wrapper
[9 Apr 2018 12:33] Hussam Shaheen
example result from generated .sql file using mysqldump: 

--
-- Table structure for table `location_country_cities`
--

DROP TABLE IF EXISTS `location_country_cities`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `location_country_cities` (
  `country_code` varchar(2) NOT NULL,
  `city` varchar(255) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
[9 Apr 2018 12:38] MySQL Verification Team
Thank you for the feedback. I couldn't repeat with source build, I am using default options for server and client, please check your my.cnf.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.41 Source distribution 2018-APR-04

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

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 5.6 > CREATE DATABASE colla;
Query OK, 1 row affected (0,00 sec)

mysql 5.6 > USE colla
Database changed
mysql 5.6 >
mysql 5.6 > CREATE TABLE userdb_entities (
    -> id INTEGER NOT NULL AUTO_INCREMENT,
    -> dn VARCHAR(100) NOT NULL UNIQUE,
    -> type ENUM('person', 'group') NOT NULL,
    -> created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    -> PRIMARY KEY (id)
    -> ) Engine=InnoDB, CHARACTER SET utf8 COLLATE utf8_unicode_ci;
Query OK, 0 rows affected (0,40 sec)

mysql 5.6 > exit
Bye
miguel@tikal:~/dbs $ 5.6/bin/mysqldump -uroot -p --socket=/tmp/mysql56.sock colla
Enter password:
-- MySQL dump 10.13  Distrib 5.6.41, for Linux (x86_64)
--
-- Host: localhost    Database: colla
-- ------------------------------------------------------
-- Server version       5.6.41

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `userdb_entities`
--

DROP TABLE IF EXISTS `userdb_entities`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `userdb_entities` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `dn` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
  `type` enum('person','group') COLLATE utf8_unicode_ci NOT NULL,
  `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `dn` (`dn`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `userdb_entities`
--

LOCK TABLES `userdb_entities` WRITE;
/*!40000 ALTER TABLE `userdb_entities` DISABLE KEYS */;
/*!40000 ALTER TABLE `userdb_entities` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2018-04-09  9:35:13