当前位置:网站首页>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.
边栏推荐
猜你喜欢
随机推荐
Go (一) 基础部分3 -- 数组,切片(append,copy),map,指针
Go (一) 基础部分2 -- if条件判断,for循环语句
令人愉快的 Nuxt3 教程 (二): 快速轻松地搭建博客
D-PHY
经典论文-ResNet
-飞机大战-
uni-app 滚动到顶部/指定位置
Flask,7
Haproxy服务监控
【myPow,2次幂,3次幂..代码实现】
Makefile介绍
【按位取反,逻辑操作符,条件操作符,逗号表达式,下标引用,函数调用,结构体】操作符后续+表达式求值(上)
【打印菱形】
图的最短路径的核心——松弛技术
Makefile语法
Browser multi-threaded off-screen rendering, compression and packaging scheme
pta a.1003 的收获
【DC-5靶场渗透】
《录取通知》 观后感
飞机大战完整版