将文件内容导入到MySQL中

it2022-05-09  36

1、作用

把文件系统的内容导入到数据库中

2、语法

load data infile "文件名" into table 表名 fields terminated by "分隔符" lines terminated by "\n"

3、练习

把/etc/passwd文件中的内容导入到库t1下的userinfo表中 tarena : x : 1000 : 1000 : tarena,,, 用户名 密码 UID GID 用户描述 :/home/tarena : /bin/bash ----->有登录权限 主目录 登录权限 /bin/false ----->没有登录权限 /usr/sbin/nologin ----->没有登录权限

4、操作步骤

1、在数据中创建对应的表 2、将要导入的文件拷贝到数据库的默认搜索路径中 3、将系统文件导入到创建的表中 1、创建表 create table userinfo( username char(20), password char(1), uid int, gid int, comment varchar(50), homedir varchar(50), shell varchar(50) ); 2、将要导入的文件拷贝到数据库的默认搜索路径中 1、如何查看数据库的默认搜索路径 show variables like "secure_file_priv"; 2、sudo cp /etc/passwd /var/lib/mysql-files/ 3、执行数据导入语句 load data infile "/var/lib/mysql-files/passwd" into table userinfo fields terminated by ":" lines terminated by "\n" 4、在userinfo表中第一列添加一个id字段,类型为int,设置为主键带自增长属性 alter table userinfo add id int primary key auto_increment first

转载于:https://www.cnblogs.com/taoke2016/p/9002616.html


最新回复(0)