MySQL修改字符集

: No such file or directory===========================*/ 字符集报错

bash: /bin: Is a directory
bash: /bin: Is a directory
: No such file or directory===========================================*/
bash: $’\r’: command not found
bash: $’\ruse’: command not foundMySQL修改字符集
注:用的是滴滴云Linux的服务器
在执行如下的sql语句时出现如下错误:


root@2275fd015386:/# source /usr/src/sql/crebas.sql 
: No such file or directory===========================================*/
bash: /bin: Is a directory
bash: /bin: Is a directory
: No such file or directory===========================================*/
bash: $'\r': command not found
bash: $'\ruse': command not found
bash: drop: command not found
bash: $'\r': command not found
bash: $'\r': command not found
bash: drop: command not found
bash: $'\r': command not found
bash: $'\r': command not found
bash: drop: command not found
bash: $'\r': command not found
bash: $'\r': command not found
bash: drop: command not found
bash: $'\r': command not found
bash: $'\r': command not found
bash: drop: command not found
bash: $'\r': command not found
bash: $'\r': command not found
: No such file or directory===========================================*/
bash: /bin: Is a directory
: No such file or directory===========================================*/
bash: create: command not found
bash: /usr/src/sql/crebas.sql: line 22: syntax error near unexpected token `('
'ash: /usr/src/sql/crebas.sql: line 22: `   id                   varchar(32) not null,

修改字符集后解决
修改字符集的方法:

  1. 查看mysql容器的字符集
show variables like '%character%';

修改前:

+--------------------------+--------------------------------+
| Variable_name            | Value                          |
+--------------------------+--------------------------------+
| character_set_client     | latin1                         |
| character_set_connection | latin1                         |
| character_set_database   | utf8mb4                        |
| character_set_filesystem | binary                         |
| character_set_results    | latin1                         |
| character_set_server     | utf8mb4                        |
| character_set_system     | utf8                           |
| character_sets_dir       | /usr/share/mysql-8.0/charsets/ |
+--------------------------+--------------------------------+
  1. 修改字符集
    进到服务器随便选个文件夹 将容器中的两个文件复制到选择的文件夹中
docker cp db0:/etc/mysql/my.cnf my.cnf
docker cp db0:/etc/mysql/conf.d/mysql.cnf mysql.cnf
  1. 编辑(增加)my.cnf (容器),增加的内容如下:
[client]
default-character-set=utf8
# ...

[mysqld]
character-set-server = utf8
# ...

  1. 编辑(增加)mysql.cnf (docker mysql8)客户端配置文件
[mysql]
default-character-set = utf8
  1. 修改完成后再将修改好的文件复制到容器中
docker cp  my.cnf  db0:/etc/mysql/my.cnf
docker cp  mysql.cnf db0:/etc/mysql/conf.d/mysql.cnf

  1. 修改完成后重启容器
docker restart db0
  1. 再次进入mysql命令行查看字符集如下:
+--------------------------+--------------------------------+
| Variable_name            | Value                          |
+--------------------------+--------------------------------+
| character_set_client     | utf8                           |
| character_set_connection | utf8                           |
| character_set_database   | utf8                           |
| character_set_filesystem | binary                         |
| character_set_results    | utf8                           |
| character_set_server     | utf8                           |
| character_set_system     | utf8                           |
| character_sets_dir       | /usr/share/mysql-8.0/charsets/ |
+--------------------------+--------------------------------+

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值