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:
-
-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