3步搞定纯真IP数据导入到MySQL的方法详解_MySQL
bitsCN.com
前提: 你会用vi。 很明显,本文是在Linux下测试通过的。本文用的是MySQL命令行工具,如果你不会,用phpMyAdmin应该也可以。
第1步: 下载纯真IP数据,解压存成ip.txt。
详解:这一步不用详解了吧。如果你这一步都不会,下面就不用看了。
第2步: 用vi 编辑 ip.txt。
# vi ip.txt
在vi界面下输入如下命令:
:%s//s/+/;/
一共重复输入3次。
存盘退出:
:wq
详解:ip.txt有4列。分别是起始ip,结束ip,地区,说明。列之间用不等数量的空格间隔。为了将此文本文件到入到mysql,需要处理掉这些空格。但是只能处理掉前3列的空格,最后一列中的空格要保留。vi中输入的命令意思是,把每一行第一个和其连续的空格替换成字符';'。
%s代表全局搜索替换。/s代表空格。/+代表尽可能多地匹配前面的字符。;代表替换成';'
第3步: 导入MySQL
创建MySQL表
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
为避免出现乱码, region和comments字段的Collation设为gbk_chinese_ci
导入ip.txt到ips数据库的ip表
# mysqlimport -p你的密码 --local --delete --fields-terminated-by=';' ips ip.txt
完成!
详解:mysqlimport可以导入一个文本文件到数据库的表中。前提是表的名字与文本文件名相同,并且表的字段与文本文件也对应起来。
--fields-terminated-by=';' 意思是字段用';'间隔开来。
--delete意思是,如果表已存在,导入前清空表中数据。bitsCN.com

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

BITGet is a cryptocurrency exchange that provides a variety of trading services including spot trading, contract trading and derivatives. Founded in 2018, the exchange is headquartered in Singapore and is committed to providing users with a safe and reliable trading platform. BITGet offers a variety of trading pairs, including BTC/USDT, ETH/USDT and XRP/USDT. Additionally, the exchange has a reputation for security and liquidity and offers a variety of features such as premium order types, leveraged trading and 24/7 customer support.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Gate.io is a popular cryptocurrency exchange that users can use by downloading its installation package and installing it on their devices. The steps to obtain the installation package are as follows: Visit the official website of Gate.io, click "Download", select the corresponding operating system (Windows, Mac or Linux), and download the installation package to your computer. It is recommended to temporarily disable antivirus software or firewall during installation to ensure smooth installation. After completion, the user needs to create a Gate.io account to start using it.

Ouyi OKX, the world's leading digital asset exchange, has now launched an official installation package to provide a safe and convenient trading experience. The OKX installation package of Ouyi does not need to be accessed through a browser. It can directly install independent applications on the device, creating a stable and efficient trading platform for users. The installation process is simple and easy to understand. Users only need to download the latest version of the installation package and follow the prompts to complete the installation step by step.

Causes and solutions for errors when using PECL to install extensions in Docker environment When using Docker environment, we often encounter some headaches...

Many website developers face the problem of integrating Node.js or Python services under the LAMP architecture: the existing LAMP (Linux Apache MySQL PHP) architecture website needs...

Using python in Linux terminal...
