利用file權限讀取/etc/passwd

歡迎關注MySQL 8.0必知必會系列課程。

    MySQL8.0必知必會-自動化部署            https://edu.51cto.com/course/16368.html
    MySQL8.0必知必會之參數標準化配置        https://edu.51cto.com/course/16358.html



1 背景介紹

把OS的文件導入到數據庫中

2、語法

load data infile "文件名"

into table 表名

fields terminated by "分隔符"

lines terminated by "\n"

3、練習

把/etc/passwd文件中的內容導入到的userinfo表中

root:x:0:0:root:/root:/bin/bash

用戶名:密碼:UID:GID:用戶描述:主目錄:登錄權限



2 操作步驟

在數據中創建對應的表

將要導入的文件拷貝到數據庫的默認搜索路徑中

將系統文件導入到創建的表中

  • 創建表

create table userinfo(

username char(20),

password char(1),

uid int,

gid int,

comment varchar(50),

homedir varchar(50),

shell varchar(50)

);

  • 將要導入的文件拷貝到數據庫的默認搜索路徑中

如何查看數據庫的默認搜索路徑

show variables like "secure_file_priv";

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章