MySQL data-related operations, clearing tables, importing txt files, and counting the number of records

import command

The following operations are performed in MySQL

clear data table

TRUNCATE TABLE [tablename]

Calculate the number of records in the table

select count(1) from pirsnp;

Import a txt file, the txt file does not contain a header, specify the header in the command and ensure consistency

#设置允许导入
set global local_infile = 1;
#导入
LOAD DATA LOCAL INFILE '/xxx/xxx.txt' INTO TABLE [tablename](columnname1,columnname2,...);

Other common commands

1. Split files under Linux
#每一千万行数据分割为一个文件,split_file0,split_file1,...
split -l 10000000 test.txt -d -a 1 split_file
2. Regular expressions for finding blank lines in TXT, preventing blank lines from importing null values
^(\s*)\n

3. CMD merge files
type *.txt >>xxx\xxx\xxx\pirsnp.txt

import example

The following file is imported into the database. The headers are a, b, and c. There are two records in total. You need to delete the header of the first line first
insert image description here
and then execute

LOAD DATA LOCAL INFILE '/root/1.txt' INTO TABLE testTable(a,b,c);

Guess you like

Origin blog.csdn.net/qq_44839815/article/details/121389010