aaemnnosttv / wp-cli-valet-command

Harness the power of Laravel Valet for creating fully functional WordPress installs in seconds.
https://aaemnnost.tv/wp-cli-commands/valet/
299 stars 31 forks source link

Ability to set the database collation and charset on creation #54

Open edwardjosephbennett opened 5 years ago

edwardjosephbennett commented 5 years ago

Hi,

Is it possible to set the Database Collation and Database Charset when running wp valet new site?

I have been tinkering around with this and valet and find the setup fantastically useful, although this issue has been bugging me for a while.

At the minute when running the new site command, a database gets created with the following collation: screenshot 2019-01-23 at 15 13 23

I have a plugin that creates database tables, which throws up errors on activation regarding and incorrect collation type. See an example of stack trace below:

Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1253 COLLATION 'utf8mb4_unicode_520_ci' is not valid for CHARACTER SET 'utf8' in .../wp-content/plugins/.../vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:77
Stack trace:
#0 .../wp-content/plugins/.../vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php(77): PDO->prepare('set names 'utf8...', Array)
#1 .../wp-content/plugins/.../vendor/illuminate/database/Connectors/MySqlConnector.php(56): Doctrine\DBAL\Driver\PDOConnection->prepare('set names 'utf8...')
#2 .../wp-content/plugins/.../vendor/illuminate/database/Connectors/MySqlConnector.php(30): Illuminate\Database\Connectors\MySqlConnector->configureEncoding(Object(Doctrine\DBAL\Driver\PDOConnection), Array)

The issue I think sits around the either the plugin trying to set names 'utf8...' or the original collation being set with the 520 part is wrong.

Current MySQL Version is: Ver 8.0.13 for osx10.14 on x86_64 (Homebrew)

Any help on how this issue may be worked around either from WP-CLI Valets point of view or WP-CLI itself is appreciated.

Thanks, Ed

aaemnnosttv commented 5 years ago

Hey there 👋

Currently the valet new command does not offer an option to provide the db charset or collation.

What you can do however, is add (temporarily?) these as defaults in your wp-cli config file like so:

core config:
  dbcharset: yourcharset
  dbcollate: yourcollation

Let me know if this does it for you!

neilgee commented 5 months ago

Trying to use core config for the charset but I need to mix it with config create - can I use both in the same file?, as now where I position it makes the other not be set


  admin_user: admin
  admin_password: "password"
  admin_email: me@you.com
  locale: en_AU
  # Subcommand defaults (e.g. `wp config create`)
config create:
    dbuser: root
    dbpass: 
    extra-php: |
        define( 'WP_DEBUG', true );
        define( 'WP_DEBUG_LOG', true );
        define( 'WP_DEBUG_DISPLAY', true );
        @ini_set( 'display_errors', 0 );
        define( 'WP_POST_REVISIONS', 7 );
core config:
    dbcharset: utf8mb4
neilgee commented 5 months ago

Actually works if I include it in config create


  admin_password: "password"
  admin_email: me@you.com
  locale: en_AU
  # Subcommand defaults (e.g. `wp config create`)
config create:
    dbuser: root
    dbpass: 
    dbcharset: utf8mb4
    extra-php: |
        define( 'WP_DEBUG', true );
        define( 'WP_DEBUG_LOG', true );
        define( 'WP_DEBUG_DISPLAY', true );
        @ini_set( 'display_errors', 0 );
        define( 'WP_POST_REVISIONS', 7 );