diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 842ae1b1..945b0790 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -80,10 +80,10 @@ $ export PYTEST_HOST=localhost $ export PYTEST_USER=mycli $ export PYTEST_PASSWORD=myclirocks $ export PYTEST_PORT=3306 -$ export PYTEST_CHARSET=utf8 +$ export PYTEST_CHARSET=utf8mb4 ``` -The default values are `localhost`, `root`, no password, `3306`, and `utf8`. +The default values are `localhost`, `root`, no password, `3306`, and `utf8mb4`. You only need to set the values that differ from the defaults. If you would like to run the tests as a user with only the necessary privileges, diff --git a/README.md b/README.md index a082ec98..9fe91fd1 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,14 @@ Thanks to [PyMysql](https://github.com/PyMySQL/PyMySQL) for a pure python adapte Mycli is tested on macOS and Linux, and requires Python 3.10 or better. +To connect to MySQL versions earlier than 5.5, you may need to set the following in `~/.myclirc`: + +``` +# character set for connections without --charset being set at the CLI +default_character_set = utf8 +``` + +or set `--charset=utf8` when invoking MyCLI. ### Configuration and Usage diff --git a/changelog.md b/changelog.md index c2e8b335..7af467ac 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,7 @@ TBD Features -------- * Add `--unbuffered` mode which fetches rows as needed, to save memory. +* Default to standards-compliant `utf8mb4` character set. Bug Fixes diff --git a/mycli/main.py b/mycli/main.py index 731489fd..d7936132 100755 --- a/mycli/main.py +++ b/mycli/main.py @@ -514,7 +514,7 @@ def connect( socket = socket or cnf["socket"] or cnf["default_socket"] or guess_socket_location() passwd = passwd if isinstance(passwd, str) else cnf["password"] - charset = charset or cnf["default-character-set"] or "utf8" + charset = charset or self.config["main"].get("default_character_set") or cnf["default-character-set"] or "utf8mb4" # Favor whichever local_infile option is set. use_local_infile = False diff --git a/mycli/myclirc b/mycli/myclirc index 62113850..66ac242d 100644 --- a/mycli/myclirc +++ b/mycli/myclirc @@ -131,6 +131,9 @@ enable_pager = True # Choose a specific pager pager = 'less' +# character set for connections without --charset being set at the CLI +default_character_set = utf8mb4 + [keys] # possible values: auto, fzf, reverse_isearch control_r = auto diff --git a/test/myclirc b/test/myclirc index d3cdd4e9..d4061fa5 100644 --- a/test/myclirc +++ b/test/myclirc @@ -129,6 +129,9 @@ enable_pager = True # Choose a specific pager pager = less +# character set for connections without --charset being set at the CLI +default_character_set = utf8mb4 + [keys] # possible values: auto, fzf, reverse_isearch control_r = auto diff --git a/test/utils.py b/test/utils.py index e9010952..aa944303 100644 --- a/test/utils.py +++ b/test/utils.py @@ -16,7 +16,7 @@ USER = os.getenv("PYTEST_USER", "root") HOST = os.getenv("PYTEST_HOST", "localhost") PORT = int(os.getenv("PYTEST_PORT", "3306")) -CHARSET = os.getenv("PYTEST_CHARSET", "utf8") +CHARSET = os.getenv("PYTEST_CHARSET", "utf8mb4") SSH_USER = os.getenv("PYTEST_SSH_USER", None) SSH_HOST = os.getenv("PYTEST_SSH_HOST", None) SSH_PORT = int(os.getenv("PYTEST_SSH_PORT", "22"))