问题:mysql -B -N --host=localhost --user=root --password=secret
-e "select CONCAT('alter table ',TABLE_SCHEMA,'.',
TABLE_NAME,' charset=utf8mb4_bin;')
from information_schema.TABLES WHERE TABLE_SCHEMA = 'usda_nndsr';
select CONCAT('alter table ',TABLE_SCHEMA,'.',TABLE_NAME,' alter column ',
COLUMN_NAME,' charset=utf8mb4_bin;')
from information_schema.COLUMNS WHERE TABLE_SCHEMA ='usda_nndsr';" |
mysql --host=localhost --user=root --password=secret
但消息显示:mysql: mysql: [Warning] Using a password on the command line interface can be insecure.[Warning] Using a password on the command line interface can be insecure.
ERROR 1115 (42000) at line 1: Unknown character set: 'utf8mb4_bin'
我想要utf8mb4_bin,因为我听说MySQL utf8不是仅使用3个字节的真正utf8。
如何编辑查询或命令进行更改,
MySQL版本:$ mysql -V
mysql Ver 14.14 Distrib 5.7.32, for Linux (x86_64) using EditLine wrapper
答案1:
对应的字符集是utf8mb4。
5.5之前的版本没有字符集utf8mb4.
这将转换一个表的所有文本(VARCHAR和TEXT)列:ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4;
相关文章