-1

i'm new to mysql database. i'm trying to create maintable by joining existing two tables in MySQL. The following command i had used. But it throws the following error.

create table maintable as select * from table1 union select * from table2;

Error 126 (HY000): incorrect key file for table 'c:\temp'; try to repair it
i had googled and increased tmp_table_size to 2G. My configuration file looks like this.

[client]

port=3306

[mysql]

default-character-set=UTF8

[mysqld]
port=3306
max_allowed_packet=128M
basedir="C:/Program Files/MySQL/MySQL Server 5.5/"
datadir="C:/ProgramData/MySQL/MySQL Server 5.5/Data/"
character-set-server=UTF8
default-storage-engine=INNODB
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
max_connections=100
query_cache_size=0
table_cache=2G
tmp_table_size=2G
max_heap_table_size=2G
thread_cache_size=32
myisam_max_sort_file_size=100G
myisam_sort_buffer_size=126M

read_buffer_size=128K
read_rnd_buffer_size=612K
sort_buffer_size=566K
innodb_additional_mem_pool_size=512M
innodb_flush_log_at_trx_commit=1
innodb_log_buffer_size=50M
innodb_buffer_pool_size=127M
innodb_log_file_size=24M

But nothing seems to resolve the error... Your help is really appreciated. Thank you

Veeramani Natarajan
  • 192
  • 2
  • 4
  • 11
  • 3
    possible duplicate of [MySQL, Error 126: Incorrect key file for table](http://stackoverflow.com/questions/19003106/mysql-error-126-incorrect-key-file-for-table) – Tim Biegeleisen Aug 13 '15 at 11:56

1 Answers1

1

If both tables have same no. of columns and in same order as it will be as you are using union which can work only if no. of columns will be same then you can use any one approach out of below, which will be faster than simple insert method-

Through dump:

step1: take table1 backup through dump with structure and data.

Step2: take table2 dump of only data.

Step3: restore table1.

Step4: restore table2 data only in table1.


Through export/import method:

Step1: take both table backup in csv.

select * INTO OUTFILE 'd:\\backup\\table1.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\r\n' FROM table1;

select * INTO OUTFILE 'd:\\backup\\table1.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\r\n' FROM table2;

Step3: now import both csv data into table, first create table-

LOAD DATA LOCAL INFILE 'd:\\backup\\table1.csv' INTO TABLE mytable FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n' ignore 1 lines;

LOAD DATA LOCAL INFILE 'd:\\backup\\table2.csv' INTO TABLE mytable FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n' ignore 1 lines;
Zafar Malik
  • 6,734
  • 2
  • 19
  • 30