mysql数据备份-导入与导出数据

December 17, 2023
测试
测试
测试
测试
4 分钟阅读

数据导入:

把系统文件的内容存储到数据库服务器的表里。

命令格式: LOAD DATA INFILE “目录名/文件名” INTO TABLE 库.表名 FIELDS TERMINATED BY “分隔符” LINES TERMINATED BY “\n”;

把系统文件/etc/passwd的内容存储到userdb库下的user表里。

(/etc/passwd的内容格式:root:x:uid:gid:root:/root:/bin/bash) >create database userdb; >create table userdb.user(  name char(25),  password char(1),  uid int(2),  gid int(2),  comment varchar(50),  homedir char(30),  shell char(25),  index(name)  );

>desc userdb.user; >select * from userdb.user; > show variables like "secure_file_priv"; >system cp /etc/passwd /var/lib/mysql-files/ > load data infile "/var/lib/mysql-files/passwd" into table  userdb.user

 fields terminated by ":"  lines terminated by "\n"; > select * from userdb.user; > alter table userdb.user add  id int(2) primary key  auto_increment first; >select * from userdb.user where id=25; >select * from userdb.user where id<=10;

导入数据时,设置搜索文件路径

#vim /etc/my.cnf [mysqld] secure_file_priv="/mydata" #mkdir /mydata #chown mysql /mydata #setenforce 0 #systemctl restart mysqld

> show variables like "secure_file_priv";

数据导出

把表记录存储到系统文件里。 语法格式 sql查询 into outfile "目录/文件名"; SELECT查询.. .. INTO OUTFILE “目录名/文件名”

FIELDS TERMINATED BY “分隔符” LINES TERMINATED BY “\n”;

>select user,host from mysql.user into outfile "/mydata/a.txt"; >system cat /mydata/a.txt

继续阅读

更多来自我们博客的帖子

如何安装 BuddyPress
由 测试 December 17, 2023
经过差不多一年的开发,BuddyPress 这个基于 WordPress Mu 的 SNS 插件正式版终于发布了。BuddyPress...
阅读更多
Filter如何工作
由 测试 December 17, 2023
在 web.xml...
阅读更多
如何理解CGAffineTransform
由 测试 December 17, 2023
CGAffineTransform A structure for holding an affine transformation matrix. ...
阅读更多