之前都在宿主机直接yum install mysql,后面数据迁移都时候,发现不能一下把所有都data迁移,想想还是docker部署挂载data盘好迁移一点
安装命令
mkdir -p /data/mysql
chmod 777 -R /data/mysql
docker run -d -p 3306:3306 --name mysql \ --restart=always \ -v /data/mysql/log:/var/log/mysql \ -v /data/mysql/data:/var/lib/mysql \ -v /data/mysql/conf:/etc/mysql \ -e MYSQL_ROOT_PASSWORD=123456 \ mysql:5.7.26
修改root密码
默认密码在docker run 语句里MYSQL_ROOT_PASSWORD=root,密码是root,
docker exec -it mysql mysql -u root -p
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456'
创建数据库
create database flamingo default character set utf8 default collate utf8_general_ci;
常见错误
我这边是挂载nfs启动mysql的,所以有权限问题
chown: changing ownership of '/var/lib/mysql/performance_schema/threads.frm': Operation not permitted chown: changing ownership of '/var/lib/mysql/performance_schema/events_stages_current.frm': Operation not permitted
解决方式:
找到mysql数据文件夹的权限id,下面显示是:1024 users
[root@k8s-ops data]# ls -lrt /data/mysql/
总用量 0
drwxrwxrwx 1 1024 users 0 6月 2 2021 conf
drwxrwxrwx 1 1024 users 0 5月 10 17:28 log
drwxrwxrwx 1 1024 users 482 5月 10 17:54 data
- 运行mysql的添加–user 1024:users
docker run -d -p 3306:3306 --name mysql --user 1024:users --restart=always -v /data/mysql/log:/var/log/mysql -v /data/mysql/data:/var/lib/mysql -v /data/mysql/conf:/etc/mysql -e MYSQL_ROOT_PASSWORD=123456 mysql:5.7.26
原创文章,作者:站长,如若转载,请注明出处:https://wsppx.cn/1445/%e7%bd%91%e7%ab%99%e9%83%a8%e7%bd%b2/