wp-cli / db-command

Performs basic database operations using credentials stored in wp-config.php.
MIT License
71 stars 57 forks source link

Problem with the wp db export charset #242

Closed QuatorzeCommunications closed 1 year ago

QuatorzeCommunications commented 1 year ago

Bug Report

Describe the current, buggy behavior

I have a wordpress installation with the database using utf8mb4 and when I export, it choose utf8 as default-charset-encoding instead of utf8mb4.


Debug (db): Final MySQL command: /usr/bin/env mysql --no-defaults --no-auto-rehash --batch --skip-column-names --host='localhost' --user='mydb_wp' --default-character-set='utf8' --execute='SELECT CCSA.character_set_name FROM information_schema.TABLES T, information_schema.COLLATION_CHARACTER_SET_APPLICABILITY CCSA WHERE CCSA.collation_name = T.table_collation AND T.table_schema = '\''mydb_wp'\'' AND T.table_name LIKE '\''%_posts'\'';' (0.253s) Debug (db): Detected character set of the posts table: utf8mb4 utf8mb4 utf8mb4 utf8mb4 utf8mb4. (0.267s) Debug (db): Running initial shell command: /usr/bin/env mysqldump --no-defaults (0.267s) Debug (db): Associative arguments: {"result-file":"mydb_wp-2023-09-26-33c898d.sql"} (0.267s) Debug (db): Final MySQL command: /usr/bin/env mysqldump --no-defaults 'mydb_wp' --no-tablespaces --host='localhost' --user='mydb_wp' --default-character-set='utf8' --result-file='mydb_wp-2023-09-26-33c898d.sql' (0.267s)

Describe how other contributors can replicate this bug

The issue command is wp db export --debug

Describe what you would expect as the correct outcome

Since utf8mb4 was detected I would have expected that the mysqldump command to set --default-character-set='utf8mb4'

Let us know what environment you are running this on

OS: Linux 5.14.0-284.25.1.el9_2.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Aug 2 14:53:30 UTC 2023 x86_64
Shell:  /bin/bash
PHP binary: /opt/remi/php81/root/usr/bin/php
PHP version:    8.1.23
php.ini used:   /etc/opt/remi/php81/php.ini
MySQL binary:   /usr/bin/mysql
MySQL version:  mysql  Ver 15.1 Distrib 10.11.5-MariaDB, for Linux (x86_64) using  EditLine wrapper
SQL modes:  
WP-CLI root dir:    phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:  phar://wp-cli.phar/vendor
WP_CLI phar path:   /home/wp/public_html
WP-CLI packages dir:    
WP-CLI cache dir:   /home/wp/.wp-cli/cache
WP-CLI global config:   
WP-CLI project config:  
WP-CLI version: 2.8.1

Provide a possible solution

Provide additional context/Screenshots

danielbachhuber commented 1 year ago

Thanks for the report, @QuatorzeCommunications !

Since utf8mb4 was detected I would have expected that the mysqldump command to set --default-character-set='utf8mb4'

This is what should be happening:

https://github.com/wp-cli/db-command/blob/0908bf5182b830c302199037070292e20d9f4ea6/src/DB_Command.php#L579-L594

What is DB_CHARSET set for this WordPress install?

huguesjoyal commented 1 year ago

?

Sorry, I've openned issue in the wrong account, but the DB_CHARSET was set to UTF-8

danielbachhuber commented 1 year ago

Huh. Can you share the command you're using to export?

huguesjoyal commented 1 year ago

Hi,

I was only doing a standard : wp db export wp db import


I've tested it on another new installation and settings the same settings on another server and it didn't broke. For now we probably can close this issue. If I encounter this problem I'll try to find more information. (mysql.ini, version, etc.)

Thanks