spring boot应用需要连接到服务器上的数据库,为了方便日后迁移,我想将数据库安装在docker上,刚开始参考的是菜鸟教程,其上的步骤是正确的,只是会遇到一些问题:菜鸟上强调docker的容器和数据要分离,因此要创建相应的文件夹,主要包括conf、logs以及data,然后在运行docker run命令的时候,以-v参数进行本机host文件夹路径到容器内部相应文件夹的路径映射就可以了,但是菜鸟上面的命令是有问题的,我使用的命令如下
1
docker run --name some-mysql -p 3306:3306 -v /root/mysql/conf:/etc/mysql/conf.d -v /root/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql
[client] # 新增客户端的编码 default-character-set=utf8 [mysql] # 新增客户端的编码,缺省 default-character-set=utf8 [mysqld] # # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Recommended in standard MySQL setup sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES # 新增 关于character_set_server的编码设置 init-connect='SET NAMES utf8' character-set-server = utf8 [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid