docker的mysql镜像为1.8版本
首先去mysql容器中寻找mysql.cnf文件
通常在以下地址:
[root@iz2zei9wv79ob7vwy7y1jcz tmp]# docker exec -it mysql01 bash
root@e868fadad232:/# ls
bin dev entrypoint.sh home lib64 mnt proc run srv tmp var
boot docker-entrypoint-initdb.d etc lib media opt root sbin sys usr
root@e868fadad232:/# cd etc
root@e868fadad232:/etc# cd mysql
root@e868fadad232:/etc/mysql# ls
conf.d my.cnf my.cnf.fallback
root@e868fadad232:/etc/mysql# cd conf.d
root@e868fadad232:/etc/mysql/conf.d# ls
docker.cnf mysql.cnf
root@e868fadad232:/etc/mysql/conf.d# exit
将容器文件cp到物理机随意目录
[root@iz2zei9wv79ob7vwy7y1jcz tmp]# docker cp mysql01:/etc/mysql/conf.d/mysql.cnf /tmp
[root@iz2zei9wv79ob7vwy7y1jcz tmp]# ls
mysql.cnf
对配置文件进行编辑
# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# The MySQL Client configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
将文件cp会mysql 容器对应位置,并重启容器使配置生效
[root@iz2zei9wv79ob7vwy7y1jcz tmp]# docker cp /tmp/mysql.cnf mysql01:/etc/mysql/conf.d/
[root@iz2zei9wv79ob7vwy7y1jcz tmp]# docker restart mysql01
mysql01
登陆mysql 查看对应字符集设置
mysql> show variables like'char%';
+--------------------------+--------------------------------+
| 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/ |
+--------------------------+--------------------------------+
8 rows in set (0.01 sec)