下载镜像
docker pull mariadb
my.cnf的内容
[mysqld]
user=mysql
character-set-server=utf8mb4
default_authentication_plugin=mysql_native_password
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
运行镜像
sudo docker run -d -v /root/conf/my.cnf:/etc/mysql/conf.d/my.cnf -v /root/data/mysql:/var/lib/mysql -p 3307:3306 -e MYSQL_ROOT_PASSWORD=123456 –name mariadb1117 mariadb
备注:3307是宿主机端口,3306是镜像端口
连接数据库
mysql -P 3307 –protocol tcp -p
查看镜像日志
docker logs containerId
登录镜像
docker exec -it containerId /bin/bash
创建用户
create user’新用户名’@’localhost’identified by ‘新密码’;
grant all privileges on *.* to ‘新用户名’@’%’ identified by ‘新密码’;
flush privileges;