<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
用法:
select xxx into outfile '/path/file' from table_name; mysql>select * into outfile '/back/emp3.sql' from emp;
無論是什麼儲存引擎,本身是一種資料匯出的方法,同時可以用來輔助備份,它可以對一個表的其中一列或者某幾列做備份,如果是多列的話用逗號隔開
方法一:
load data local infile '/path/file' into table table_name; mysql> load data local infile '/back/emp.sql' into table emp;
說明:該方法要求在編譯資料庫時要加上--enable-local-infile引數才可以使用
方法二:
# mysqlimport dbname /path/filename
說明:filename 必須和資料庫裡面表名一樣
# 建立表 mysql> create table t1(id int, name varchar(32)); # 插入資料 mysql> insert into t1 values(1,'haha'),(2,'wowo'),(3,'lili'),(4,'yoyo'); # 檢視表 mysql> select * from t1; +------+------+ | id | name | +------+------+ | 1 | haha | | 2 | wowo | | 3 | lili | | 4 | yoyo | +------+------+ # 備份 mysql> select id, name into outfile '/tmp/back_mysql' from t1; Query OK, 4 rows affected (0.01 sec)
[root@Admin ~]# cat /tmp/back_mysql 1 haha 2 wowo 3 lili 4 yoyo
mysql> delete from t1 where id=3; Query OK, 1 row affected (0.00 sec) mysql> select * from t1; +------+------+ | id | name | +------+------+ | 1 | haha | | 2 | wowo | | 4 | yoyo | +------+------+ 3 rows in set (0.00 sec) mysql> load data local infile '/tmp/back_mysql' into table t1; Query OK, 4 rows affected (0.00 sec) Records: 4 Deleted: 0 Skipped: 0 Warnings: 0 mysql> select * from t1; +------+------+ | id | name | +------+------+ | 1 | haha | | 2 | wowo | | 4 | yoyo | | 1 | haha | | 2 | wowo | | 3 | lili | | 4 | yoyo | +------+------+ 7 rows in set (0.00 sec)
View Code
建立一個表,把系統裡的/etc/passwd匯入資料庫
create table password( username varchar(40), password char(5), uid int, gid int, comment varchar(30), homedir varchar(30), shell varchar(30));
處理passwd檔案,將:替換成製表符
[root@Admin ~]# sed -n 's/:/t/gp' /etc/passwd >/tmp/passwd
方法一:
mysql> load data local infile '/tmp/passwd' into table password;
mysql> select * from password; +---------------+----------+-------+-------+------------------------------+------------------------+----------------+ | username | password | uid | gid | comment | homedir | shell | +---------------+----------+-------+-------+------------------------------+------------------------+----------------+ | root | x | 0 | 0 | root | /root | /bin/bash | | bin | x | 1 | 1 | bin | /bin | /sbin/nologin | | daemon | x | 2 | 2 | daemon | /sbin | /sbin/nologin | | adm | x | 3 | 4 | adm | /var/adm | /sbin/nologin | | lp | x | 4 | 7 | lp | /var/spool/lpd | /sbin/nologin | | sync | x | 5 | 0 | sync | /sbin | /bin/sync | | shutdown | x | 6 | 0 | shutdown | /sbin | /sbin/shutdown | | halt | x | 7 | 0 | halt | /sbin | /sbin/halt | | mail | x | 8 | 12 | mail | /var/spool/mail | /sbin/nologin | | uucp | x | 10 | 14 | uucp | /var/spool/uucp | /sbin/nologin | | operator | x | 11 | 0 | operator | /root | /sbin/nologin | | games | x | 12 | 100 | games | /usr/games | /sbin/nologin | | gopher | x | 13 | 30 | gopher | /var/gopher | /sbin/nologin | | ftp | x | 14 | 50 | FTP User | /var/ftp | /sbin/nologin | | nobody | x | 99 | 99 | Nobody | / | /sbin/nologin | | dbus | x | 81 | 81 | System message bus | / | /sbin/nologin | | usbmuxd | x | 113 | 113 | usbmuxd user | / | /sbin/nologin | | rpc | x | 32 | 32 | Rpcbind Daemon | /var/lib/rpcbind | /sbin/nologin | | rtkit | x | 499 | 499 | RealtimeKit | /proc | /sbin/nologin | | avahi-autoipd | x | 170 | 170 | Avahi IPv4LL Stack | /var/lib/avahi-autoipd | /sbin/nologin | | vcsa | x | 69 | 69 | virtual console memory owner | /dev | /sbin/nologin | | abrt | x | 173 | 173 | | /etc/abrt | /sbin/nologin | | rpcuser | x | 29 | 29 | RPC Service User | /var/lib/nfs | /sbin/nologin | | nfsnobody | x | 65534 | 65534 | Anonymous NFS User | /var/lib/nfs | /sbin/nologin | | haldaemon | x | 68 | 68 | HAL daemon | / | /sbin/nologin | | ntp | x | 38 | 38 | | /etc/ntp | /sbin/nologin | | apache | x | 48 | 48 | Apache | /var/www | /sbin/nologin | | saslauth | x | 498 | 76 | Saslauthd user | /var/empty/saslauth | /sbin/nologin | | postfix | x | 89 | 89 | | /var/spool/postfix | /sbin/nologin | | gdm | x | 42 | 42 | | /var/lib/gdm | /sbin/nologin | | pulse | x | 497 | 496 | PulseAudio System Daemon | /var/run/pulse | /sbin/nologin | | sshd | x | 74 | 74 | Privilege-separated SSH | /var/empty/sshd | /sbin/nologin | | tcpdump | x | 72 | 72 | | / | /sbin/nologin | | mysql | x | 27 | 27 | MySQL Server | /var/lib/mysql | /bin/bash | +---------------+----------+-------+-------+------------------------------+------------------------+----------------+
方法二:
通過mysqlimport進行匯入
注意:匯入的檔名必須和表名一樣
[root@Admin ~]# cp /etc/passwd /tmp/password [root@Admin ~]# mysqlimport --fields-terminated-by=':' --lines-terminated-by='n' login '/tmp/password' login.password: Records: 34 Deleted: 0 Skipped: 0 Warnings: 0
說明:檔案不需處理, 通過--fields-terminated-by=':' 和 --lines-terminated-by='n' 將passwd檔案中的冒號替換為製表符
mysql> select * from password; +---------------+----------+-------+-------+------------------------------+------------------------+----------------+ | username | password | uid | gid | comment | homedir | shell | +---------------+----------+-------+-------+------------------------------+------------------------+----------------+ | root | x | 0 | 0 | root | /root | /bin/bash | | bin | x | 1 | 1 | bin | /bin | /sbin/nologin | | daemon | x | 2 | 2 | daemon | /sbin | /sbin/nologin | | adm | x | 3 | 4 | adm | /var/adm | /sbin/nologin | | lp | x | 4 | 7 | lp | /var/spool/lpd | /sbin/nologin | | sync | x | 5 | 0 | sync | /sbin | /bin/sync | | shutdown | x | 6 | 0 | shutdown | /sbin | /sbin/shutdown | | halt | x | 7 | 0 | halt | /sbin | /sbin/halt | | mail | x | 8 | 12 | mail | /var/spool/mail | /sbin/nologin | | uucp | x | 10 | 14 | uucp | /var/spool/uucp | /sbin/nologin | | operator | x | 11 | 0 | operator | /root | /sbin/nologin | | games | x | 12 | 100 | games | /usr/games | /sbin/nologin | | gopher | x | 13 | 30 | gopher | /var/gopher | /sbin/nologin | | ftp | x | 14 | 50 | FTP User | /var/ftp | /sbin/nologin | | nobody | x | 99 | 99 | Nobody | / | /sbin/nologin | | dbus | x | 81 | 81 | System message bus | / | /sbin/nologin | | usbmuxd | x | 113 | 113 | usbmuxd user | / | /sbin/nologin | | rpc | x | 32 | 32 | Rpcbind Daemon | /var/lib/rpcbind | /sbin/nologin | | rtkit | x | 499 | 499 | RealtimeKit | /proc | /sbin/nologin | | avahi-autoipd | x | 170 | 170 | Avahi IPv4LL Stack | /var/lib/avahi-autoipd | /sbin/nologin | | vcsa | x | 69 | 69 | virtual console memory owner | /dev | /sbin/nologin | | abrt | x | 173 | 173 | | /etc/abrt | /sbin/nologin | | rpcuser | x | 29 | 29 | RPC Service User | /var/lib/nfs | /sbin/nologin | | nfsnobody | x | 65534 | 65534 | Anonymous NFS User | /var/lib/nfs | /sbin/nologin | | haldaemon | x | 68 | 68 | HAL daemon | / | /sbin/nologin | | ntp | x | 38 | 38 | | /etc/ntp | /sbin/nologin | | apache | x | 48 | 48 | Apache | /var/www | /sbin/nologin | | saslauth | x | 498 | 76 | Saslauthd user | /var/empty/saslauth | /sbin/nologin | | postfix | x | 89 | 89 | | /var/spool/postfix | /sbin/nologin | | gdm | x | 42 | 42 | | /var/lib/gdm | /sbin/nologin | | pulse | x | 497 | 496 | PulseAudio System Daemon | /var/run/pulse | /sbin/nologin | | sshd | x | 74 | 74 | Privilege-separated SSH | /var/empty/sshd | /sbin/nologin | | tcpdump | x | 72 | 72 | | / | /sbin/nologin | | mysql | x | 27 | 27 | MySQL Server | /var/lib/mysql | /bin/bash | +---------------+----------+-------+-------+------------------------------+------------------------+----------------+ 34 rows in set (0.00 sec)
把使用者登入系統的資訊儲存到資料庫裡
需要顯示如下:
select username 使用者名稱, tty 登入終端, ip 來源IP from login;
mysql> create table login( username varchar(40), tty varchar(40), ip varchar(50));
處理登入資料並儲存在檔案裡:
[root@Admin ~]# last -f /var/log/wtmp |sed -r '/^reboot|^wtmp/d' |awk '{print $1"t"$2"t"$3}'|tee /tmp/login
方法一:
mysql> load data local infile '/tmp/login' into table login;
方法二:
[root@Admin ~]# mysqlimport login '/tmp/login'
檢視結果:
mysql> select username 使用者名稱, tty 登入終端, ip 來源IP from login;
+-----------+--------------+---------------+
| 使用者名稱 | 登入終端 | 來源IP |
+-----------+--------------+---------------+
| root | pts/2 | 192.168.1.131 |
| root | pts/1 | 192.168.1.131 |
| root | pts/1 | 192.168.1.131 |
| root | pts/0 | :0.0 |
| root | tty1 | :0 |
| root | pts/0 | :0.0 |
| root | tty1 | :0 |
| | | |
+-----------+--------------+---------------+
8 rows in set (0.00 sec)
到此這篇關於MySQL邏輯備份into outfile的文章就介紹到這了,更多相關MySQL邏輯備份內容請搜尋it145.com以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援it145.com!
相關文章
<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
综合看Anker超能充系列的性价比很高,并且与不仅和iPhone12/苹果<em>Mac</em>Book很配,而且适合多设备充电需求的日常使用或差旅场景,不管是安卓还是Switch同样也能用得上它,希望这次分享能给准备购入充电器的小伙伴们有所
2021-06-01 09:31:42
除了L4WUDU与吴亦凡已经多次共事,成为了明面上的厂牌成员,吴亦凡还曾带领20XXCLUB全队参加2020年的一场音乐节,这也是20XXCLUB首次全员合照,王嗣尧Turbo、陈彦希Regi、<em>Mac</em> Ova Seas、林渝植等人全部出场。然而让
2021-06-01 09:31:34
目前应用IPFS的机构:1 谷歌<em>浏览器</em>支持IPFS分布式协议 2 万维网 (历史档案博物馆)数据库 3 火狐<em>浏览器</em>支持 IPFS分布式协议 4 EOS 等数字货币数据存储 5 美国国会图书馆,历史资料永久保存在 IPFS 6 加
2021-06-01 09:31:24
开拓者的车机是兼容苹果和<em>安卓</em>,虽然我不怎么用,但确实兼顾了我家人的很多需求:副驾的门板还配有解锁开关,有的时候老婆开车,下车的时候偶尔会忘记解锁,我在副驾驶可以自己开门:第二排设计很好,不仅配置了一个很大的
2021-06-01 09:30:48
不仅是<em>安卓</em>手机,苹果手机的降价力度也是前所未有了,iPhone12也“跳水价”了,发布价是6799元,如今已经跌至5308元,降价幅度超过1400元,最新定价确认了。iPhone12是苹果首款5G手机,同时也是全球首款5nm芯片的智能机,它
2021-06-01 09:30:45