Skip to content

Commit 3d71763

Browse files
authored
Merge pull request #935 from dbcli/RW/utf8mb4-default-charset
Default to standards-compliant utf8mb4 character set
2 parents 6f6bdec + ffe9267 commit 3d71763

7 files changed

Lines changed: 19 additions & 4 deletions

File tree

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ $ export PYTEST_HOST=localhost
8080
$ export PYTEST_USER=mycli
8181
$ export PYTEST_PASSWORD=myclirocks
8282
$ export PYTEST_PORT=3306
83-
$ export PYTEST_CHARSET=utf8
83+
$ export PYTEST_CHARSET=utf8mb4
8484
```
8585
86-
The default values are `localhost`, `root`, no password, `3306`, and `utf8`.
86+
The default values are `localhost`, `root`, no password, `3306`, and `utf8mb4`.
8787
You only need to set the values that differ from the defaults.
8888
8989
If you would like to run the tests as a user with only the necessary privileges,

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ Thanks to [PyMysql](https://github.com/PyMySQL/PyMySQL) for a pure python adapte
142142

143143
Mycli is tested on macOS and Linux, and requires Python 3.10 or better.
144144

145+
To connect to MySQL versions earlier than 5.5, you may need to set the following in `~/.myclirc`:
146+
147+
```
148+
# character set for connections without --charset being set at the CLI
149+
default_character_set = utf8
150+
```
151+
152+
or set `--charset=utf8` when invoking MyCLI.
145153

146154
### Configuration and Usage
147155

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ TBD
44
Features
55
--------
66
* Add `--unbuffered` mode which fetches rows as needed, to save memory.
7+
* Default to standards-compliant `utf8mb4` character set.
78

89

910
Bug Fixes

mycli/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ def connect(
514514
socket = socket or cnf["socket"] or cnf["default_socket"] or guess_socket_location()
515515

516516
passwd = passwd if isinstance(passwd, str) else cnf["password"]
517-
charset = charset or cnf["default-character-set"] or "utf8"
517+
charset = charset or self.config["main"].get("default_character_set") or cnf["default-character-set"] or "utf8mb4"
518518

519519
# Favor whichever local_infile option is set.
520520
use_local_infile = False

mycli/myclirc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ enable_pager = True
131131
# Choose a specific pager
132132
pager = 'less'
133133

134+
# character set for connections without --charset being set at the CLI
135+
default_character_set = utf8mb4
136+
134137
[keys]
135138
# possible values: auto, fzf, reverse_isearch
136139
control_r = auto

test/myclirc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ enable_pager = True
129129
# Choose a specific pager
130130
pager = less
131131

132+
# character set for connections without --charset being set at the CLI
133+
default_character_set = utf8mb4
134+
132135
[keys]
133136
# possible values: auto, fzf, reverse_isearch
134137
control_r = auto

test/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
USER = os.getenv("PYTEST_USER", "root")
1717
HOST = os.getenv("PYTEST_HOST", "localhost")
1818
PORT = int(os.getenv("PYTEST_PORT", "3306"))
19-
CHARSET = os.getenv("PYTEST_CHARSET", "utf8")
19+
CHARSET = os.getenv("PYTEST_CHARSET", "utf8mb4")
2020
SSH_USER = os.getenv("PYTEST_SSH_USER", None)
2121
SSH_HOST = os.getenv("PYTEST_SSH_HOST", None)
2222
SSH_PORT = int(os.getenv("PYTEST_SSH_PORT", "22"))

0 commit comments

Comments
 (0)