Nekonzistence collations (MySQL, MariaDB)
Otázka
Co mám dělat, když mám v databázi nekonzistenci collations (MySQL, MariaDB)?
Odpověď
Nasledující platí jen pro MySQL a MariaDB databázi :
Od verze 8.2 musí být collation schématu konzistentní s collation jednotlivých tabulek a sloupců jinak Infoport nedovolí zmigrovat. Admin databáze musí sjednotit collation na schématu.
Pro zobrazení collation na sloupečkách použijte query:
SELECT DISTINCT COLLATION_NAME
FROM information_schema.columns
WHERE TABLE_SCHEMA = 'schemaName' AND TABLE_NAME <> '__EfMigrationsHistory' AND COLLATION_NAME IS NOT null
Pro zobrazení collation na tabulkách použijte query:
SELECT DISTINCT TABLE_COLLATION
FROM information_schema.`TABLES`
WHERE TABLE_SCHEMA = 'schemaName' AND TABLE_NAME <> '__EfMigrationsHistory'
Pro zobrazení collation na schématu použijte query:
SELECT DEFAULT_COLLATION_NAME
FROM information_schema.SCHEMATA
WHERE SCHEMA_NAME = 'schemaName' AND TABLE_NAME <> '__EfMigrationsHistory'
Pro zobrazení tabulek, sloupců a jejich collation použijte query:
SELECT TABLE_NAME, COLUMN_NAME, COLLATION_NAME
FROM information_schema.columns
WHERE TABLE_SCHEMA = 'schemaName'
AND COLLATION_NAME IS NOT NULL
AND TABLE_NAME <> '__EfMigrationsHistory'
GROUP BY TABLE_NAME, COLUMN_NAME, COLLATION_NAME
Sjednoťte prosím collation a znovu spusťte Infoport.
Pro sjednocení můžete použít tyto scripty:
Pro každou tabulku:
SELECT CONCAT('ALTER TABLE `', TABLE_NAME,
'` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;')
AS 'USE `DATABASE_NAME`;'
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'DATABASE_NAME'
AND TABLE_TYPE LIKE 'BASE TABLE'
Pro každý sloupec:
SELECT CONCAT('ALTER TABLE `', TABLE_NAME, '` MODIFY COLUMN `', COLUMN_NAME,'` ',
DATA_TYPE, IF(CHARACTER_MAXIMUM_LENGTH IS NULL
OR DATA_TYPE LIKE 'longtext', '', CONCAT('(', CHARACTER_MAXIMUM_LENGTH,
')')
), ' COLLATE utf8mb4_unicode_ci;') AS 'USE `DATABASE_NAME`;'
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'DATABASE_NAME'
AND (SELECT INFORMATION_SCHEMA.TABLES.TABLE_TYPE
FROM INFORMATION_SCHEMA.TABLES
WHERE INFORMATION_SCHEMA.TABLES.TABLE_SCHEMA =
INFORMATION_SCHEMA.COLUMNS.TABLE_SCHEMA
AND INFORMATION_SCHEMA.TABLES.TABLE_NAME =
INFORMATION_SCHEMA.COLUMNS.TABLE_NAME
LIMIT 1) LIKE 'BASE TABLE'
AND DATA_TYPE IN ( 'char', 'varchar' ) /* include other types if necessary */
Pro více informací se obraťte na nás helpdesk https://www.dphelpdesk.cz/ .
No Comments