1、整库
mysqldump -u <username> -p <password> <database_name> > backup.sql
2、整表
mysqldump -u <username> -p <password> <database_name> <table_name> > backup.sql
1、整表
mysqldump -u <username> -p
--tab = /var/lib/mysql-files/ --导出目录
--fields-terminated-by=, --字段分隔符
--fields-enclosedby='"' --字段标识
--lines-terminated-by='\n' --行分隔符
<database_name> <table_name>
2、自定义sql
mysqldump不支持传入自定义sql导出csv文件,可用mysql -e命令
mysql -u <username> -p -e
"
select col1,col2
from table
into outfile '/path/file_name'
fields terminated by ','
enclosed by = '"'
line terminated by '\n'
"
注:是在mysql命令行而不是linux命令行下执行
load data infile 'path/file.txt'
into table your_table
fields terminated by ','
optionally enclosed by '"'
escaped by '\\'
lines terminated by '/n'
ignore 1 rows
转化为linux命令行
mysql -u <username> -p -e
"
load data infile 'path/file.txt'
into table your_table
fields terminated by ','
optionally enclosed by '"'
escaped by '\\'
lines terminated by '/n'
ignore 1 rows
"
show variables like '%secure_file_priv%'
解决方法:执行上述sql后,如果出来的是目录,把本地文件放到此目录下即可或者指定为空