mysql数据目录迁移
2016-05-27 09:08
495 查看
Ubuntu 14.04*64
mysql Ver 14.14 Distrib 5.5.49, for debian-linux-gnu (x86_64) using readline 6.3
一、无需通过任何工具增加数据库和数据表,包括从其他地方复制数据库
1、在mysql数据目录下新建一个目录,该目录命名成你的数据库名;
2、从其他机器拷贝数据表,注意:要拷贝*.frm/*.MYD/*.MYI三个文件;
此时使用mysql登录,使用show databases可以看到新加入的目录为新的数据库名,通过use newdatabase和show tables都可以正常使用,但是“select * from 表名”提示如下错误:ERROR 1017 (HY000): Can't find file: './newdatabase/tablename.frm' (errno: 13),这个问题可以通过第三步解决。
3、修改新建的目录(数据库)的所有权:chown -R mysql:root newdatabase
4、通过mysql登录检查是否正常,经验证正常
二、整个数据库迁移
原文:http://article.my-addr.com/?show=linux_ubuntu_change_datadir-move_mysql_database_to_other_path
Open the terminal
Stop MySQL with the command
1、 /etc/init.d/mysql stop
Move existing data directory (which is located in /var/lib/mysql) to new dir /usr/new_datadir using the command
2、 mv /var/lib/mysql /usr/new_datadir
Create symlink from new dir to old one
3、 ln -s /usr/new_datadir /var/lib/mysql
Don't chnage /etc/mysql/my.cnf =)))
Ubuntu uses some security software called AppArmor that specifies the areas of your filesystem applications are allowed to access. Unless you modify the AppArmor profile
for MySQL, you'll never be able to restart MySQL with the new datadir location.
In the terminal, enter the command
4、 vim /etc/apparmor.d/usr.sbin.mysqld
Duplicate the lines beginning with /var/lib/mysql and replace duplicated strings with /usr/new_datadirIn my case it was:
/var/lib/mysql/ r,
/var/lib/mysql/** rwk,
#
/usr/new_datadir r,
/usr/new_datadir** rwk,
Restart the AppArmor profiles with the command
5、 /etc/init.d/apparmor restart
Restart MySQL with the command
6、/etc/init.d/mysql restart
MySQL should now start without any errors, have fun! See also article How to move the mysql datadir, Ubuntu change datadir issue
经测试该步骤是正确的
注意:在第二步如果使用cp的话,会生成新的目录,这样需要通过chown -R mysql:mysql /usr/new_datadir修改目录的权限才能成功启动,否则在/var/log/mysql/error.log中会报如下错误:
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
InnoDB: File name ./ibdata1
InnoDB: File operation call: 'create'.
InnoDB: Cannot continue operation.
mysql Ver 14.14 Distrib 5.5.49, for debian-linux-gnu (x86_64) using readline 6.3
一、无需通过任何工具增加数据库和数据表,包括从其他地方复制数据库
1、在mysql数据目录下新建一个目录,该目录命名成你的数据库名;
2、从其他机器拷贝数据表,注意:要拷贝*.frm/*.MYD/*.MYI三个文件;
此时使用mysql登录,使用show databases可以看到新加入的目录为新的数据库名,通过use newdatabase和show tables都可以正常使用,但是“select * from 表名”提示如下错误:ERROR 1017 (HY000): Can't find file: './newdatabase/tablename.frm' (errno: 13),这个问题可以通过第三步解决。
3、修改新建的目录(数据库)的所有权:chown -R mysql:root newdatabase
4、通过mysql登录检查是否正常,经验证正常
二、整个数据库迁移
原文:http://article.my-addr.com/?show=linux_ubuntu_change_datadir-move_mysql_database_to_other_path
Open the terminal
Stop MySQL with the command
1、 /etc/init.d/mysql stop
Move existing data directory (which is located in /var/lib/mysql) to new dir /usr/new_datadir using the command
2、 mv /var/lib/mysql /usr/new_datadir
Create symlink from new dir to old one
3、 ln -s /usr/new_datadir /var/lib/mysql
Don't chnage /etc/mysql/my.cnf =)))
Ubuntu uses some security software called AppArmor that specifies the areas of your filesystem applications are allowed to access. Unless you modify the AppArmor profile
for MySQL, you'll never be able to restart MySQL with the new datadir location.
In the terminal, enter the command
4、 vim /etc/apparmor.d/usr.sbin.mysqld
Duplicate the lines beginning with /var/lib/mysql and replace duplicated strings with /usr/new_datadirIn my case it was:
/var/lib/mysql/ r,
/var/lib/mysql/** rwk,
#
/usr/new_datadir r,
/usr/new_datadir** rwk,
Restart the AppArmor profiles with the command
5、 /etc/init.d/apparmor restart
Restart MySQL with the command
6、/etc/init.d/mysql restart
MySQL should now start without any errors, have fun! See also article How to move the mysql datadir, Ubuntu change datadir issue
经测试该步骤是正确的
注意:在第二步如果使用cp的话,会生成新的目录,这样需要通过chown -R mysql:mysql /usr/new_datadir修改目录的权限才能成功启动,否则在/var/log/mysql/error.log中会报如下错误:
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
InnoDB: File name ./ibdata1
InnoDB: File operation call: 'create'.
InnoDB: Cannot continue operation.
相关文章推荐
- 打开MySQL数据库远程访问的权限
- mysql的备份与恢复
- MySql各种查询
- 做Mysql主从同步过滤时,应使用replicate_wild_do_table和replicate_wild_ignore_table参数
- mysqldump参数--lock-all-tables和--single-transaction的区别
- mysql-sql 插入、删除、修改
- 一个脚本安装mysql
- 操作数据表中的记录
- MySQL数据库远程访问权限如何打开(两种方法)
- 数据库Mysql性能优化详解
- Mysql常用命令大全
- Mysql 表分区技术
- mysql5.6 gtid复制
- sublime Text3 on window8.1远程连接mysql on ubuntu14.04 Sever
- Mysql查询使用Limit优化
- mysql gtid问题
- 备份和恢复你的MySQL数据库
- MySQL数据库学习笔记之简单查找(知识点)
- mysql错误
- spark-mysql中文过滤问题