

Loading the CSV data into the MySQL temporary table RESULT="$(mysql -h $DBHOST -u $DBUSER -p$DBPASS $DBNAME -e 'CREATE TABLE `ip2location_database_tmp` (`ip_from` INT(10) UNSIGNED ZEROFILL NOT NULL,`ip_to` INT(10) UNSIGNED ZEROFILL NOT NULL,`country_code` CHAR(2) NOT NULL,`country_name` VARCHAR(64) NOT NULL,`region_name` VARCHAR(128) NOT NULL,`city_name` VARCHAR(128) NOT NULL,`latitude` DOUBLE NULL DEFAULT NULL,`longitude` DOUBLE NULL DEFAULT NULL,`zip_code` VARCHAR(12) NULL DEFAULT NULL,`time_zone` VARCHAR(8) NULL DEFAULT NULL,`isp` VARCHAR(255) NOT NULL,`domain` VARCHAR(128) NOT NULL,`net_speed` VARCHAR(8) NOT NULL,`idd_code` VARCHAR(5) NOT NULL,`area_code` VARCHAR(30) NOT NULL,`weather_station_code` VARCHAR(10) NOT NULL,`weather_station_name` VARCHAR(128) NOT NULL,`mcc` VARCHAR(128) NULL DEFAULT NULL,`mnc` VARCHAR(128) NULL DEFAULT NULL,`mobile_brand` VARCHAR(128) NULL DEFAULT NULL,`elevation` INT(10) NOT NULL,`usage_type` VARCHAR(11) NOT NULL,INDEX `idx_ip_from` (`ip_from`),INDEX `idx_ip_to` (`ip_to`),INDEX `idx_isp` (`isp`)) ENGINE=MyISAM ' 2>&1)"Įrror "Unable to create temporary table."

wget -O database.zip -q $TOKEN\&file=$CODE 2>&1 If the download is not successful then an error message will be shown and the script will terminate itself. "Įrror "Failed to create /tmp/ip2location"ĭownloading the zipped data file from the web server if thenĮcho -n "Create temporary directory. An error message will be shown if the folder cannot be created and the script will terminate itself. If the temporary folder does not exist, it will be created. for a in wget unzip mysql wc find grep doĭone Creating the temporary folder for storing the downloaded zipped data file If any of them are not installed, an error message will be shown and the script will terminate itself. Some Linux packages like wget, unzip, mysql, wc, find and grep are needed for this script to run. Under the Configuration section of the script, you will need to key in all the relevant login information in the fields below: # Configurationįor most cases, you shouldn’t have to modify anything else in the script but we will still explain what is going on in case you want to modify the code.

Configure login detailsįirstly, we need to set up some login details for the IP2Location web server as well as the MySQL server information.
IP2LOCATION DOWNLOAD CODE
We will explain what each part of the code does as we go through the whole process. The whole shell script code is at the end of this article.
IP2LOCATION DOWNLOAD HOW TO
We will show how to download the IP2Location DB24 csv data from the web server and then unzip it before loading the data into a MySQL server on a Linux platform. Here is a guide for users to fully automate the updating of their IP2Location DB24 database.
