您的位置:首页 > 运维架构 > Docker

Docker-如何设置mysql容器中字符集

2019-08-05 13:13 1261 查看

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/ |
+----
3ff7
----------------------+--------------------------------+
8 rows in set (0.01 sec)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: