Home Database Mysql Tutorial 3步搞定纯真IP数据导入到MySQL的方法详解_MySQL

3步搞定纯真IP数据导入到MySQL的方法详解_MySQL

Jun 01, 2016 pm 01:19 PM
linux

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

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve the permissions problem encountered when viewing Python version in Linux terminal? How to solve the permissions problem encountered when viewing Python version in Linux terminal? Apr 01, 2025 pm 05:09 PM

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

BITGet official website installation (2025 beginner's guide) BITGet official website installation (2025 beginner's guide) Feb 21, 2025 pm 08:42 PM

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 permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

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...

Get the gate.io installation package for free Get the gate.io installation package for free Feb 21, 2025 pm 08:21 PM

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 installation package is directly included Ouyi okx installation package is directly included Feb 21, 2025 pm 08:00 PM

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.

Why does an error occur when installing an extension using PECL in a Docker environment? How to solve it? Why does an error occur when installing an extension using PECL in a Docker environment? How to solve it? Apr 01, 2025 pm 03:06 PM

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

How to efficiently integrate Node.js or Python services under LAMP architecture? How to efficiently integrate Node.js or Python services under LAMP architecture? Apr 01, 2025 pm 02:48 PM

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...

How to solve permission issues when using python --version command in Linux terminal? How to solve permission issues when using python --version command in Linux terminal? Apr 02, 2025 am 06:36 AM

Using python in Linux terminal...

See all articles