Docker从宿主机挂载卷到Mysql镜像之坑

admin 2019-10-06 23:03:14 0 0 Docker 316 复制链接

想实现容器内数据持久化,于是把宿主机的mysql数据挂载到了容器内,结果,后来发现mysql show databases都提示

ERROR 1018 (HY000): Can't read dir of '.' (errno: 13 - Permission denied)


百度了下说是人为操作修改了mysql datadir的权限,还好之前看到过一篇帖子说,挂载了之后要手动修改回原来的root用户和组。

chown -R mysql:mysql /var/lib/mysql #/your/path/to/datadir


我的/var/lib/mysql是我的mysql datadir,你的不一定和我一样,可以通过以下命令进入mysql中查询:

mysql> show variables like '%dir%';
+-----------------------------------------+----------------------------+
| Variable_name                           | Value                      |
+-----------------------------------------+----------------------------+
| basedir                                 | /usr/                      |
| binlog_direct_non_transactional_updates | OFF                        |
| character_sets_dir                      | /usr/share/mysql/charsets/ |
| datadir                                 | /var/lib/mysql/            |
| ignore_db_dirs                          |                            |
| innodb_data_home_dir                    |                            |
| innodb_log_group_home_dir               | ./                         |
| innodb_max_dirty_pages_pct              | 75.000000                  |
| innodb_max_dirty_pages_pct_lwm          | 0.000000                   |
| innodb_tmpdir                           |                            |
| innodb_undo_directory                   | ./                         |
| lc_messages_dir                         | /usr/share/mysql/          |
| plugin_dir                              | /usr/lib/mysql/plugin/     |
| slave_load_tmpdir                       | /tmp                       |
| tmpdir                                  | /tmp                       |
+-----------------------------------------+----------------------------+
15 rows in set (0.00 sec)



评论(0)

    还没有评论,快来抢沙发吧!