Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

An example of exporting database files for statistics + deduplication under Linux

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

This article is about the export of database files for statistics + deduplication examples under Linux. The editor thought it was very practical, so I shared it with you as a reference. Let's follow the editor and have a look.

1. Export database tables to a text file

Mysql-h host-P port-u user-p password-A database-e "select email,domain,time from ent_login_01_000" > ent_login_01_000.txt

The total number of login users in the last 3 months is broken down by month, and there are 128 tables per month, all of which are exported to files, with a total of 80g.

2. Grep found all 2018-12 2019-01 2019-02

Find. /-type f-name "ent_login_*" | xargs cat | grep "2018-12" > 2018-12.txt

Find. /-type f-name "ent_login_*" | xargs cat | grep "2019-01" > 2019-01.txt

Find. /-type f-name "ent_login_*" | xargs cat | grep "2019-02" > 2019-02.txt

3. Use awk sort and uniq to take out only the previous users, and go to repeat lines first

Cat 2019-02.txt | awk- F "'{print $1" @ "$2}'| sort- T / mnt/public/phpdev/187_test/tmp/ | uniq > 2019-02-awk-sort-uniq.txt

Cat 2019-01.txt | awk- F "'{print $1" @ "$2}'| sort- T / mnt/public/phpdev/187_test/tmp/ | uniq > 2019-01-awk-sort-uniq.txt

Cat 2018-12.txt | awk- F "'{print $1" @ "$2}'| sort- T / mnt/public/phpdev/187_test/tmp/ | uniq > 2018-12-awk-sort-uniq.txt

Uniq only removes consecutive duplicate lines, and sort can arrange lines into consecutive-T because the temporary directory of / tmp is occupied by default, and my root directory is not enough, so change the temporary directory.

These files occupy more than 100 gigabytes.

Thank you for reading! The example of exporting database files for statistics + de-duplication under Linux is shared here. I hope the above content can be helpful to you, so that you can learn more knowledge. If you think the article is good, you can share it and let more people see it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report