时间:2021-07-01 10:21:17 帮助过:16人阅读
二 恢复逻辑备份。
#方法一: [root@egon backup]# mysql -uroot -p123 < /backup/all.sql #方法二: mysql> use db1; mysql> SET SQL_LOG_BIN=0; mysql> source /root/db1.sql #注:如果备份/恢复单个库时,可以修改sql文件 DROP database if exists school; create database school; use school;
三 表的导入与导出
SELECT... INTO OUTFILE 导出文本文件 示例: mysql> SELECT * FROM school.student1 INTO OUTFILE ‘student1.txt‘ FIELDS TERMINATED BY ‘,‘ //定义字段分隔符 OPTIONALLY ENCLOSED BY ‘”‘ //定义字符串使用什么符号括起来 LINES TERMINATED BY ‘\n‘ ; //定义换行符 mysql 命令导出文本文件 示例: # mysql -u root -p123 -e ‘select * from student1.school‘ > /tmp/student1.txt # mysql -u root -p123 --xml -e ‘select * from student1.school‘ > /tmp/student1.xml # mysql -u root -p123 --html -e ‘select * from student1.school‘ > /tmp/student1.html LOAD DATA INFILE 导入文本文件 mysql> DELETE FROM student1; mysql> LOAD DATA INFILE ‘/tmp/student1.txt‘ INTO TABLE school.student1 FIELDS TERMINATED BY ‘,‘ OPTIONALLY ENCLOSED BY ‘”‘ LINES TERMINATED BY ‘\n‘;
#可能会报错 mysql> select * from db1.emp into outfile ‘C:\\db1.emp.txt‘ fields terminated by ‘,‘ lines terminated by ‘\r\n‘; ERROR 1238 (HY000): Variable ‘secure_file_priv‘ is a read only variable #数据库最关键的是数据,一旦数据库权限泄露,那么通过上述语句就可以轻松将数据导出到文件中然后下载拿走,因而mysql对此作了限制,只能将文件导出到指定目录 在配置文件中 [mysqld] secure_file_priv=‘C:\\‘ #只能将数据导出到C:\\下 重启mysql 重新执行上述语句 报错:Variable ‘secure_file_priv‘ is a read only
数据库操作——数据库的备份
标签:文件 inf sed load data var htm 字段 数据库权限 定义