Warning: Creating default object from empty value in /www/htdocs/v030397/mysql-qotd/wp-content/plugins/sitepress-multilingual-cms/sitepress.class.php on line 4991

Warning: Creating default object from empty value in /www/htdocs/v030397/mysql-qotd/wp-content/plugins/sitepress-multilingual-cms/sitepress.class.php on line 4993
Question 77: How do you copy the table? – MySQL Question of the Day

Skip to content

By plogi in mysql questions

You want to copy a MyIsam table the fasted way possible from database qotd1 to qotd2 inside the same instance.
Check the scenario below:

create database qotdt1;
create database qotdt2;

use qotdt1;
set @a:=0;
create table qt1 (primary key (tid),index(ttype,tdate))
  engine=myisam
  select @a:=@a+1 as tid,rand()*99999999 as tsum, floor(rand()*3) as ttype,
         adddate('2010-01-01',interval rand()*360 day) as tdate
  from information_schema.columns, information_schema.tables limit 100000 ;

select @@global.datadir;

You decide, that using operating system means will be the fastest way.
Which of the procedures below will make a consistent copy?
(Find all correct answers)
 

a) FLUSH TABLES WITH READ LOCK;
   Copy [datadir]/qotdt1/qt1.* to [datadir]/qotdt2/
   UNLOCK TABLES;
   FLUSH TABLES;

b) Shutdown the instance.
   Copy [datadir]/qotdt1/qt1.* to [datadir]/qotdt2/
   Startup the instance.

c) LOCK TABLE qotdt1.qt1 READ;
   FLUSH TABLES;
   Copy [datadir]/qotdt1/qt1.* to [datadir]/qotdt2/
   UNLOCK TABLES;
   FLUSH TABLES;

 
[MyISAM table maintenance - Backup]

Tags: , ,

Comment Feed

One Response

  1. plogi3. July 2010 @ 15:15:14


    a b c

    a and c are online backups.
    Of those, c will disturb the least, as only one table is locked.
    It is important, that the LOCK and UNLOCK commands are done in the same database connection.
    So the connection needs to stay open, while the files are copied.
    b is an offline backup.

You must be logged in to post a comment.