docker下载mysql镜像并运行

记录docker安装mysql数据库

1.下载mysql镜像
	docker pull mysql:8.0
2.运行mysql镜像
	docker run 	\
	-p 3306:3306 \
	--name=mysql001 \
	-v /docker/mysql/data:/var/lib/mysql \
	-v /docker/mysql/conf/my.cnf:/etc/mysql/my.cnf \
	--privileged=true \
	-e MYSQL_ROOT_PASSWORD=123456 \
	-d mysql:8.0 \
	--lower_case_table_names=1
	——————————————————————————————————————————————————————————————————————————————
			--lower_case_table_names=1 让mysql不区分大小写
			--privileged=true 让容器内root用户拥有root权限
3.进入mysql容器  
	docker exec -it 容器名 bash
4.登录mysql
	mysql -u root -p
5.mysql重置密码(8.0版本以上需要登录修改密码)
	ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'P@ssw0rd';
	flush privileges;
退出mysql和容器都是Ctrl+D

my.cnf文件的配置

[client]
default-character-set=utf8mb4
 
[mysql]
default-character-set=utf8mb4
 
[mysqld]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql
secure-file-priv= NULL
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
max_connections=10000
default-time_zone='+8:00'
character-set-client-handshake=FALSE
character_set_server=utf8mb4
collation-server=utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci'
# Custom config should go here
!includedir /etc/mysql/conf.d/

你可能感兴趣的:(java开发)