当前位置:网站首页>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 05:41:00 【Lanzhou Qianfan】
Execute the mysql script file in the docker container and solve the garbled characters
I searched the Internet a lot, is it so difficult to execute a piece of code in the container mysql?Make it very complicated.
So I recorded it myself. Although it was simple, I was afraid that I would forget it later, so I searched for it for a long time.
The requirement now is to import my sql file and let mysql in docker execute it.
Note that mysql is in the docker container. If you only import it to the host, and then enter the container to execute the sql file, it will tell you that it cannot be opened, because the outside of the host and the inside of the container are relatively isolated.The path to the host may be found inside the container.
Therefore, all we have to do is copy the host's sql file into the container, and then let it execute, and that's it.
I put the sql file here, this is the common directory I used to mount the docker sql file, of course, you can put it anywhere now.
To copy into the container, you need to findcontainer.
First enumerate, look at the running container, you will know the id corresponding to mysql.
docker ps
Then we specify the container through the id, which is the id of the mysql container.
We can enter the container through this command. When we go in here, we can log in to mysql here and execute the script.
docker exec -it 4f50fbeb15ee /bin/bash
ctrl+d, exit the container
But before that, we need to copy the sql file in.
docker cp /mysql/mysql/1.sql4f50fbeb15ee:/home/1.sql
After cp is the path where your host sql file is located, after the container id is the container home folder, and the other is the sql file named after I copied it.Copy here.
After copying, we go into the container again.
docker exec -it 4f50fbeb15ee /bin/bash
Then we go into the container's home
cd home
Check if there is a 1.sql in the directory. You cannot use ll to view inside the container, so use ls
ls
Some
execute in the container, justUse the path in the container, regardless of the host path.
Then we execute
source /home/1.sql
But sometimes, after execution, heThere will be some garbled characters.
So we can try to see 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;
This is effective, and then all the fields with garbled characters in my database are normal.
边栏推荐
猜你喜欢
pta a.1003 的收获
Playing with Markdown(2) - Extraction and Manipulation of Abstract Syntax Trees
用scikit-learn学习谱聚类
`monorepo` 中 `hoist` 机制导致加载配置文件路径的变化
网卡软中断过高问题优化总结
【DC-4 Range Penetration】
Sqli-labs-master shooting range 1-23 customs clearance detailed tutorial (basic)
flask 面试题 问题
【特征选取】计算数据点曲率
关于semantic-ui的cdn失效问题(怎样通过本地引用semantic-ui)
随机推荐
7.18(7)
Modelarts第一次培训
让小程序开发进入 `tailwind jit` 时代
【DC-4靶场渗透】
对角矩阵(diagonal matrix)
用C语言来实现五子棋小游戏
1.ROS环境搭建与基础工作
【XSS,文件上传,文件包含】
【特征选取】计算数据点曲率
`monorepo` 中 `hoist` 机制导致加载配置文件路径的变化
-整数求和-
Makefile 遍历子目录模板
Delightful Nuxt3 Tutorial (1): Application Creation and Configuration
HarmonyOS应用开发培训第二次作业
pta a.1030的dijkstra+DFS方法
阿凡提的难题
Length n of condensed distance matrix ‘y‘ must be a binomial coefficient
【转】最小描述长度准则MDL(Minimun Description Length)
Apache2-XXE漏洞渗透
7.21[日常]