docker mysql 文件挂载和MySQL字符集设置
docker run -p 3306:3306 --name mysql -v /usr/local/mysql/my.cnf:/etc/mysql/my.cnf -v /usr/local/mysql/logs:/logs -v /usr/local/mysql/data:/mysql_data -e MYSQL_ROOT_PASSWORD=root -d mysql:5.6
-
-p 3306:3306:将容器的3306端口映射到主机的3306端口
-
-v $PWD/conf/my.cnf:/etc/mysql/my.cnf:将主机当前目录下的conf/my.cnf挂载到容器的/etc/mysql/my.cnf
-
-v $PWD/logs:/logs:将主机当前目录下的logs目录挂载到容器的/logs
-
-v $PWD/data:/mysql_data:将主机当前目录下的data目录挂载到容器的/mysql_data
-
-e MYSQL_ROOT_PASSWORD=123456:初始化root用户的密码
show variables like'character%'; # 查看MySQL的字符集
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
修改字MySQL字符集 vim /etc/my.cnf
[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