docker创建mysql
version: "2"
services:mysql:container_name: mysql_simpleimage: mysql:5.7#env_file:#- ../env/mysql.envenvironment:MYSQL_ROOT_PASSWORD: "123456"MYSQL_USER: 'zhao'MYSQL_PASS: 'zhao'volumes:# 如果没有data文件夹会自动创建- ./data:/var/lib/mysql- ./init:/docker-entrypoint-initdb.d/ # sql初始化目录 mkidr init ; vim db_demo_01.sql ports:- "3306:3306"
db_demo_01.sql
create database db_demo default charset 'utf8';grant all on db_demo.* to 'zhao'@'%' identified by 'zhaopasswd';
flush privileges;use db_demo;
create table user
(
id int auto_increment primary key,
username varchar(64) unique not null,
email varchar(120) unique not null
);
insert into user values(1, "zhangsan","test12345@qq.com");
insert into user values(2, "lisi","12345test@qq.com");
> mysql -u root -p
默认数据mysql
> use mysql;
修改数据库的权限db_demo_01
> grant all on db_demo_01.* to 'zhao'@'%' identified by 'zhaopasswd';
> flush privileges;
> quit
> mysql -u zhao-p
> show databases;
> 显示的是指定授权后的数据库
自定字符集备份
mysqldump --default-character-set=latin1 -hlocalhost -uroot -B my_db --tables old_table > old.sql