建立目錄
# mkdir -p $PWD/mysql5.7/logs $PWD/mysql5.7/data $PWD/mysql5.7/conf # touch $PWD/mysql5.7/conf/my.cnf # 構建鏡像 # docker run -p 3306:3306 --name mysql5.7 -v $PWD/mysql5.7/conf/my.cnf:/etc/mysql/my.cnf -v $PWD/mysql5.7/logs:/logs -v $PWD/mysql5.7/data:/mysql_data -e MYSQL_ROOT_PASSWORD=root -d mysql:5.6
命令說明:mysql
- -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用戶的密碼
# mysql -u root -p # 遠程登錄受權 # GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION; # flush privileges; # 查看 # mysql -h 127.0.0.1 -u root -p