SQL数据导入/导出
问题
使用SQL语句完成下列导出、导入操作:
1)将/etc/passwd文件导入userdb库userlist表并给每条记录加编号
2)将userdb库userlist表中UID小于100的前10条记录导出,存为/dbak/ulist.txt文件
步骤
实现此案例需要按照如下步骤进行。
步骤一:将/etc/passwd文件导入MySQL数据库
导入后的表结构取决于/etc/passwd配置文件。若一时记不住各字段的含义,也可以查看passwd配置文件的man手册页,找到格式描述相关的说明,比如:
[root@dbsvr1 ~]# man 5 passwd
.. ..
There is one entry per line, and each line has the format:
account:password:UID:GID:GECOS:directory:shell
//各字段的顺序、大致用途
The field descriptions are: //以下详细解释各字段的作用
account the name of the user on the system. It should not
contain capital letters.
password the encrypted user password, an asterisk (*), or the
letter 'x'. (See pwconv(8) for an explanation of
'x'.)
UID the numerical user ID.
GID the numerical primary group ID for this user.
GECOS This field is optional and only used for informational
purposes. Usually, it contains the full username.
GECOS means General Electric Comprehensive Operating
System, which has been renamed to GCOS when GE’s large
systems division was sold to Honeywell. Dennis
Ritchie has reported: "Sometimes we sent printer out-
put or batch jobs to the GCOS machine. The gcos field
in the password file was a place to stash the informa-
tion for the $IDENTcard. Not elegant."
directory the user’s $HOME directory.
shell the program to run at login (if empty, use /bin/sh).
If set to a non-existing executable, the user will be
unable to login through login(1).
put or batch jobs to the GCOS machine. The gcos field
in the password file was a place to stash the informa-
tion for the $IDENTcard. Not elegant."
… …
1)新建userdb库、userlist表
以数据库用户root登入MySQL服务:
[root@dbsvr1 ~]# mysql -u root -p
Enter passw