失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > MySQL数据库迁移注意点

MySQL数据库迁移注意点

时间:2020-10-24 20:52:20

相关推荐

MySQL数据库迁移注意点

——废话先不罗嗦了,就让这篇草草完成的博客文章全且当做个记录吧。

以前我使用的是CentOS上的MySQL,后来因为测试需要,需要将网站以及在数据库存储的数据迁移到新的系统中进行测试,目标系统为RedHat Enterprise Linux Server(RHEL)。

由于以前从来没有迁移过数据库,因此马上就遇到了难题。

还有其他问题没有列出,仅仅就权限的问题在下面的命令以及执行结果中展示。

注:部分显示被屏蔽。

Sun25Mar05:07:30PMCST在迁移MySQL时出现的错误/usr/bin/mysqlshow:Cannotlisttablesin ********:Can'treaddirof'./********/'(errno:13)Google关键词:mysqlerrno:13解决方案:MySQL数据库的子数据库必须是mysql用户和mysql组所有,否则mysql无法读取迁移过来的数据库。[root@localhostmysql]#ls-altotal

drwxr-xr-x.7rootroot4096Mar2402:44.drwxr-xr-x.48rootroot4096Mar2402:45..-rw-r-----.1rootroot27262976Mar2402:44ibdata1-rw-r-----.1rootroot5242880Mar2402:44ib_logfile0-rw-r-----.1rootroot5242880Mar2402:44ib_logfile1drwx------.2rootroot4096Mar2402:44 ********drwx------.2rootroot4096Mar2402:44mysqldrwx------.2rootroot4096Mar2402:44performance_schemadrwx------.2rootroot4096Mar2402:44 ********

drwx------.2rootroot4096Mar2402:44 ********

[root@localhostmysql]#ls/var/lib/mysql/-altotal

drwxr-xr-x.5mysqlmysql4096Mar2516:33.drwxr-xr-x.54rootroot4096Mar2404:27..-rw-rw----.1mysqlmysql10485760Mar2516:23ibdata1-rw-rw----.1mysqlmysql5242880Mar2516:23ib_logfile0-rw-rw----.1mysqlmysql5242880Mar2516:23ib_logfile1drwx------.2rootroot4096Mar2516:33 ********

drwx------.2mysqlmysql4096Mar2516:23mysqlsrwxrwxrwx.1mysqlmysql0Mar2516:23mysql.sockdrwx------.2rootroot4096Mar2516:33 ********

[root@localhostmysql]#chown-Rmysql:mysql./********/

[root@localhostmysql]#chown-Rmysql:mysql./********/[root@localhostmysql]#servicemysqldrestartStoppingmysqld:[OK]Startingmysqld:[OK][root@localhostmysql]#ls-altotal

drwxr-xr-x.7rootroot4096Mar2402:44.drwxr-xr-x.48rootroot4096Mar2402:45..-rw-r-----.1rootroot27262976Mar2402:44ibdata1-rw-r-----.1rootroot5242880Mar2402:44ib_logfile0-rw-r-----.1rootroot5242880Mar2402:44ib_logfile1drwx------.2mysqlmysql4096Mar2402:44 ********drwx------.2rootroot4096Mar2402:44mysqldrwx------.2rootroot4096Mar2402:44performance_schemadrwx------.2rootroot4096Mar2402:44 ********drwx------.2mysqlmysql4096Mar2402:44 ********

[root@localhostmysql]#cd/var/lib/mysql/[root@localhostmysql]#ls-altotal

drwxr-xr-x.5mysqlmysql4096Mar2517:12.drwxr-xr-x.54rootroot4096Mar2404:27..-rw-rw----.1mysqlmysql10485760Mar2517:11ibdata1-rw-rw----.1mysqlmysql5242880Mar2517:12ib_logfile0-rw-rw----.1mysqlmysql5242880Mar2516:23ib_logfile1drwx------.2rootroot4096Mar2516:33 ********drwx------.2mysqlmysql4096Mar2516:23mysqlsrwxrwxrwx.1mysqlmysql0Mar2517:12mysql.sockdrwx------.2rootroot4096Mar2516:33 ********

[root@localhostmysql]#chown-Rmysql:mysql./********/[root@localhostmysql]#chown-Rmysql:mysql./********/[root@localhostmysql]#ls-altotal

drwxr-xr-x.5mysqlmysql4096Mar2517:12.drwxr-xr-x.54rootroot4096Mar2404:27..-rw-rw----.1mysqlmysql10485760Mar2517:11ibdata1-rw-rw----.1mysqlmysql5242880Mar2517:12ib_logfile0-rw-rw----.1mysqlmysql5242880Mar2516:23ib_logfile1drwx------.2mysqlmysql4096Mar2516:33 ********drwx------.2mysqlmysql4096Mar2516:23mysqlsrwxrwxrwx.1mysqlmysql0Mar2517:12mysql.sockdrwx------.2mysqlmysql4096Mar2516:33 ********

[root@localhostmysql]#servicemysqldrestartStoppingmysqld:[OK]Startingmysqld:[OK][root@localhostmysql]#

其实说的白了,就是需要注意权限指派。因为MySQL的数据库必须由mysql创建和拥有。因为一般来说,迁移过来的都是只具有root的权限——664。所以只有使用chown命令了。

附录:

chown的用法:

chown -R 用户名:用户组 目标文件或目录

其中R表示递归执行。

如果觉得《MySQL数据库迁移注意点》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。