Premise: You will use VI. Obviously, this article is tested in Linux. This document uses the MySQL command line tool. If you do not, you can use phpMyAdmin.
Step 2: Download the pure real IP data and decompress it into ip.txt.
Explanation: you do not need to explain this step. If you do not know this step, you will not need to read it below.
Step 2: Use VI to edit ip.txt.
# Vi ip.txt
On the VI interface, enter the following command:
: % S/\ s \ + /;/
Input three times in total.
Disk logout:
: WQ
Detailed Description: ip.txt has four columns. Start IP address, end IP address, and region, respectively. Use unequal spaces to separate columns. To import the text file to MySQL, you need to remove these spaces. However, only spaces in the first three columns can be processed, and spaces in the last column must be retained. The command entered in VI is to replace the first and consecutive spaces in each line with the character ';'.
% S indicates replacement of global search. \ S stands for spaces. \ + Indicates matching as many characters as possible .; Replace ';'
Step 2: Import MySQL
Create a MySQL table
CopyCode The Code is as follows: Create Table 'ips '. 'IP '(
'IP _ start' varchar (16) not null,
'IP _ end' varchar (16) null,
'Region' varchar (128) null,
'Comments' varchar (512) null
) Engine = MyISAM
To avoid garbled characters, set collation of the region and comments fields to gbk_chinese_ci.
Import ip.txt to the IP address table of the IPs Database
# Mysqlimport-p your password -- local -- delete -- fields-terminated-by = '; 'ips ip.txt
Done!
Description: mysqlimport can import a text file to a database table. The premise is that the table name is the same as the text file name, and the table field corresponds to the text file.
-- Fields-terminated-by = ';' indicates that fields are separated.
-- Delete indicates that if a table already exists, data in the table is cleared before import.