数据库文件导入导出
1.数据导入和导出
mysql数据导入和导出
导入txt文本:
mysql使用命令行导入数据:
1.方式一
Load Data InFile '文件路径' Into Table terms lines terminated by '\r\n'
问题一:
The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
mysql默认权限为null,即使不能做任何导入导出操作
解决方案是:修改my.ini中secure-file-pri 的属性为空
配置文件:
#Secure File Priv
#para:
# null:限制mysqld不允许导入导出
# /path/:限制mysqlid的导入导出只能发生在默认的path路径下
# " ":不做任何设置
[mysqld]
secure-file-priv=" "
mysql中查看变量的方法为:
show variables '具体变量名'/'表达式'
ex:
show variables secure-file-priv
show variables like '%secure%'
问题二:
[ERROR] unknown variable 'secure-file-priv='.
文件未对’secure-file-priv’声明
解决方案是:在secure-file-priv的上方添加相应的标识[mysqld]
上述问题具体配置文件如下:
[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=D:\\mysql
# 设置mysql数据库的数据的存放目录
datadir=D:\\mysql\data
# 允许最大连接数
max_connections=200
# 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
max_connect_errors=10
# 服务端使用的字符集默认为UTF8
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8
#Secure File Priv
#para:
# null:限制mysqld不允许导入导出
# /path/:限制mysqlid的导入导出只能发生在默认的path路径下
# :不做任何设置
[mysqld]
secure_file_priv=""
2.方式二
mysqlimport -h 192.168.114.129 -u root -p --fields-terminated=":" --local test D:/t_student.sql
导出txt文本:
-
sql形式
1.方式一
语法:
mysqldump -h -p -u -p database table > file
mysql执行存在的问题
-
安全问题
问题:Using a password on the command line interface can be insecure
产生原因:自mysql 5.6后加强了安全机制的管理,在命令行中法直接使用密码进行操作
-
将账号和密码配置在my.ini文件中,效果如下
//不要忘记[client],无法正常启动mysql [client] user = root password = '123456wxzr'
-
在使用时将仅通过账号申请登陆,密码二次隐藏输入,操作如下
-
-
执行问题
问题:在执行时出现不报错,且不产生相应的文件
产生原因:可能是由于频繁更改配置文件,mysql服务一切属性并没有配置完成
解决方法:关机,重启
2.方式二
source </www/example/students.sql
-
-
数据形式
mysql> SELECT * FROM passwd INTO OUTFILE '/tmp/runoob.txt' -> FIELDS TERMINATED BY ',' ENCLOSED BY '"' -> LINES TERMINATED BY '\r\n';
oracle数据导入和导出
详见连接 https://www.cnblogs.com/jasonboren/p/10926164.html
1.传统方式
exp(imp) username/password@SERVICENAME:1521 file="e:\temp.dmp"
full = y/
tabels=(table1,table2,table3,...)/
tablespaces=(tablespace1,tablespace2,tablespace3,...)/
owner(username1,username2,username3);
2.数据泵方式
expdp(impdp) username/password@SERVICENAME:1521 schemas=username dumpfile=file1.dmp logfile=file1.log directory=testdata1 remap_schema=test:test;
3.PL/SQL方式
2.DDL
1.数据库添加字段和注释
1.oracle
//添加字段
alter table table_name add(column1 type , column2 type,....)
//添加字段注释
comment on column table_name.column_n is 'comment'
2.mysql
alter table table_name add column type comment 'comment'