Ask how to import txt files to the database

Source: Internet
Author: User
Ask a question: how to import the txt file to the database? assume that [I] has a txt file containing 30 million data records for all users and passwords in CSDN. The first column is the user name, the second column is the password, and the third column is the mailbox.

Then we can get a txt file, but the first column is the mailbox, the second column is the user name, and the third column is the password.
There are more txt files with different sorting types.

I want to create a general import program. how can I store different txt files to the corresponding fields of the database in the form of "user name-password-mailbox, in this way, you can easily query the database. thank you!


Reply to discussion (solution)

We recommend that you use a mysql temporary table for the large data volume.

You can use the load data infile command to import DATA at high speed.
However, if the data file encoding is different from character_set_database, the data file will only be imported row by row.

Before import, you must have a user interaction page to manually confirm the import order.

You can use the load data infile command to import DATA at high speed.
However, if the data file encoding is different from character_set_database, the data file will only be imported row by row.

Before import, you must have a user interaction page to manually confirm the import order.

Before import, you must have a user interaction page to manually confirm the import order.
According to your meaning, does it mean that when I select to upload a file, let php read the first line of the file (usually the first line is in the same format as the following, only the length is different). after selection, let php automatically read and match?

Yes, which field of the table corresponds to which column of data must be checked clearly.

Yes, which field of the table corresponds to which column of data must be checked clearly.

Thank you for your reply.

Php loop should be okay, but I don't know how efficient it is.

This is very simple. it is the process of getting data and storing data. when getting the data, you can determine whether the first column is a mailbox. if it is a mailbox, the second column is a username and the third column is a password. If not, the first column is the user name, the second column is the password, and the third column is the mailbox. Then you can splice the string you want and store it in the database.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.