Marlin Pierce
Marlin Pierce

Reputation: 10089

The mysqldump command is omitting collation in the output

When I run mysqldump, the output does not include the table default collation for some tables. How do I include the collation for all tables?

The MySQL version is 5.7.

mysqldump --version
mysqldump  Ver 10.13 Distrib 5.7.38, for FreeBSD13.1 (amd64)

The command line is the following (but with a number of --ignore-table switches)

mysqldump --defaults-file=.fmd-acdb-dev.cnf my-db-name --set-gtid-purged=OFF

The cnf file has this:

[client]
host=localhost
user=root
password=[redacted]
max_allowed_packet=1073741824

Selections from the output follows.

/*!40000 ALTER TABLE `cluster_categorizations` DISABLE KEYS */;
-- MySQL dump 10.13  Distrib 5.7.38, for FreeBSD13.1 (amd64)
--
-- Host: localhost    Database: analyst_console_condense
-- ------------------------------------------------------
-- Server version       5.7.38-log

/*!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 */;
...
DROP TABLE IF EXISTS `false_positive_selections`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `false_positive_selections` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `display` varchar(255) DEFAULT NULL,
  `created_at` datetime NOT NULL,
  `updated_at` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
...
DROP TABLE IF EXISTS `companies`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `companies` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) DEFAULT NULL,
  `created_at` datetime NOT NULL,
  `updated_at` datetime NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `index_companies_on_name` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=32957 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

For comparison, in the source database being dumped:

show create table false_positive_selections;
CREATE TABLE `false_positive_selections` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `display` varchar(255) DEFAULT NULL,
  `created_at` datetime NOT NULL,
  `updated_at` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4

SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = 'my-schema';
utf8mb4_general_ci

SELECT TABLE_SCHEMA, TABLE_NAME, TABLE_COLLATION FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'false_positive_selections';
| my-schema | false_positive_selections | utf8mb4_general_ci |

In the destination database after restoring:

show create table false_positive_selections;
CREATE TABLE `false_positive_selections` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `display` varchar(255) DEFAULT NULL,
  `created_at` datetime NOT NULL,
  `updated_at` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci

SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = 'my-schema';
utf8mb4_0900_ai_ci

SELECT TABLE_SCHEMA, TABLE_NAME, TABLE_COLLATION FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'false_positive_selections';
| my-schema | false_positive_selections | utf8mb4_0900_ai_ci |

To confront potential differences in the default collation for the database, we are trying to standardize on setting the default collation on each table.

Upvotes: 0

Views: 60

Answers (0)

Related Questions