当前位置:网站首页>Execute the mysql script file in the docker mysql container and solve the garbled characters
Execute the mysql script file in the docker mysql container and solve the garbled characters
2022-08-03 19:02:00 【Lanzhou Qianfan】
docker 容器中执行mysqlscript files and resolve garbled characters
Searched a lot online,在容器mysqlIs it so hard to execute a piece of code in ?Make it very complicated. So record it yourself,虽然简单,But still afraid of forgetting it later,Search for a long time.
The need now is to be minesql文件导入进来,然后让docker中的mysql 来执行它.
注意mysql在docker容器中,If you only import to the host machine,Then enter the container to executesql文件的话,It will tell you that it cannot be opened,Because the outside of the host and the inside of the container are relatively isolated,It is impossible to find the path of the host inside the container.
因此,All we have to do is put the host machinesqlThe file is copied inside the container,Then let it execute,这样就好了. 我把sqlfiles are placed here,Here is what I used to do anddocker sqlOrdinary directory for file mounts,当然,You can put it anywhere now.
To copy to the inside of the container,You need to find the container first. 首先列举出来,Take a look at running containers,对应mysql的id就知道了.
docker ps然后我们通过id to specify the container,这个也就是mysql容器的id We can enter the container with this command,We go in here,You can log in heremysql,然后执行脚本.
docker exec -it 4f50fbeb15ee /bin/bashctrl+d,退出容器 但是在这之前,我们要将sql文件拷贝进来.
docker cp /mysql/mysql/1.sql 4f50fbeb15ee:/home/1.sqlcpThe back is your host computersql文件所在的路径,容器idThe latter one is the containerhome文件夹,One is named after I copied itsql文件.Copy here.
after copying,We go into the container again.
docker exec -it 4f50fbeb15ee /bin/bashThen we go into the containerhome
cd homeCheck to see if there is one in the directory1.sql,View inside the container is not availablell,所以用ls
ls有的 在容器中执行,Just use the path in the container,It has nothing to do with the host path. 然后我们就执行
source /home/1.sql但是有的时候啊,执行完毕后,He will have some gibberish.
So we can try to look at some encodings
show variables like '%char%';I changed all these encodings to utf-8
set character_set_client=utf8;
set character_set_connection=utf8;
set character_set_database=utf8;
set character_set_results=utf8;
set character_set_server=utf8;这样做是有效的,Later, the fields with garbled characters in my database were all normal.
边栏推荐
- Alibaba senior experts create a learning architecture from scratch, including Alibaba's internal technology stack PPT, PFD actual combat
- 使用range-based for循环的注意事项
- 阿里资深专家打造从零开始学架构,含阿里内部技术栈PPT、PFD实战
- MySQL如何 drop 大表
- Redis:哨兵
- 基于ck+redash构建MySQL慢日志+审计日志展示平台
- MySQL 啥时候用表锁,啥时候用行锁?这些你都应该知道吧
- Online monitoring of UPS power supply and operating environment in the computer room, the solution is here
- 【QT】入门心法
- [Dataset][VOC] Rat dataset voc format 3001 sheets
猜你喜欢

Shell:循环语句

安装porterLB

云图说丨初识华为云微服务引擎CSE

Confused!Ali was abused on the one hand, but was fortunate to be promoted to Huawei's technology, and successfully got the offer, with an annual salary of 40w

YAML中多行字符串的配置方法:|+、 |、 |-、 >+、 >、 >-的区别

基于移动GIS的环保生态管理系统

MySQL如何一劳永逸的永久支持输入中文

Protobuf Grpc使用异常 类型有未导出的方法,并且是在不同的软件包中定义

在线监控机房内的UPS电源及运行环境,解决方案来了
![[Azure Event Hub] Create Event Hub Consume Client + Custom Event Position with Azure AD Authentication](/img/fe/db506853be08398f815f4e36beee76.png)
[Azure Event Hub] Create Event Hub Consume Client + Custom Event Position with Azure AD Authentication
随机推荐
【C语言学习笔记(五)】while循环与for循环
[Dataset][VOC] Rat dataset voc format 3001 sheets
SQL代码需要供其他人复用,为什么传统的复制代码不可靠?
【夜莺监控方案】08-监控msyql集群(prometheuse+n9e+mysqld_exporter)
MySQL详细学习教程(建议收藏)
微信小程序分享功能
丙二醇二乙酸酯(Propylene Glycol Diacetate)
MySQL超详细安装教程 手把手教你安装MySQL到使用MySQL 最简单的MySQL安装方式,这种方式装,卸载也简单
typescript学习笔记
MySQL【变量、流程控制与游标】
Postgresql快照优化Globalvis新体系分析(性能大幅增强)
安装radondb mysql遇到问题
BinaryIndexedTrees树状数组
阿里巴巴政委体系-第五章、阿里政委体系建设
基于DMS的数仓智能运维服务,知多少?
[笔记]机器学习之前言介绍
字节跳动三面拿offer:网络+IO+redis+JVM+GC+红黑树+数据结构,助你快速进大厂!!
系统太多,多账号互通如何实现?
【微信小程序】NFC 标签打开小程序
VsCode预览Geojson数据