当前位置:网站首页>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.
边栏推荐
猜你喜欢
随机推荐
【Flask】Flask-SQLAlchemy的增删改查(CRUD)操作
Ansible installation and deployment detailed process, basic operation of configuration inventory
-寻找鞍点-
【命令执行与中间件漏洞】
BeanFactory和FactoryBean的区别
arm64麒麟安装paddlehub(国产化)注意事项
0.ROS常用命令
uni-app 滚动到顶部/指定位置
MySQL 索引检索原理和B+Tree数据结构详解
【XSS,文件上传,文件包含】
Delightful Nuxt3 Tutorial (1): Application Creation and Configuration
编写一个函数 reverse_string(char * string)(两种方法实现)7.26
用iPhone前摄3D人像建模,Meta:我看行
Go (二) 函数部分1 -- 函数定义,传参,返回值,作用域,函数类型,defer语句,匿名函数和闭包,panic
Go (一) 基础部分3 -- 数组,切片(append,copy),map,指针
request.getParameter的结果为on
MySQL 一些函数
Haproxy服务监控
一劳永逸解决vs编译器无法使用scanf函数
对页码的使用总结