web analytics

Monthly Archives August 2013

MongoDB backup/restore

Want to know how the backup of mongo database can be taken. Read below…

Four tools are described here.

1) mongoexport

mongoexport can be used to take the backup of a mongo database. It takes the backup to a CSV, TSV or JSON files. The syntax is as follows.


mongoexport -d db_name -c test -o db_name.csv

where -d is the database name
-c is the collection name
-o is the file name to which the backup is to be taken


2) mongoimport

mongoimport can be used to import a backup to a database. You can import from the backup file as follows.


mongoimport -d db_restore -c test –file db_name.csv

where -d is the name of the database to which the file is to be restored
-c is the collection name
–file is the backup file

3) mongodump

For those who need a complete backup of the database, you can use mongod...

Read More

PHP Script to create a test database, collection and data in mongo for testing purpose

If you need an immediate mongo database with data for test purpose, you can use the following script.

The script to be put in a nutshell – it will create a database named commandtest, create a collection named customer inside it. The collection customer has two fields – customerid, company

root@abc# vi createdb.php

<?php
$m = new MongoClient();    // connect
$db = $m->commandtest;            // create database commandtest
$chars = “abcdefghijklmnopqrstuvwxyz”;
$arraykeys = range(‘a’, ‘z’);
$collection = $db->customer;   // create collection customer
for($i=0;$i<100;$i++)
{
$string = substr(str_shuffle($chars), 0, 5);
$document = array(“customer_id” => $i.”_”.$string,”company” => $string );
$collection->insert($document);
}
?>

Now try executing the script from backend its...

Read More

Getting started with MONGO shell

New to mongo and have trouble starting???? I shall help with a few basic commands.

Inorder to go to the shell just type mongo


root@abc# mongo
MongoDB shell version: 2.4.5
connecting to: test
>

The default database that will be selected is test, but you need to work with your own databases right, let’s start.

1) Create database.

Creating database is very easy in mongo. You can just create it with the use command. The ‘use’ command selects a database if it exists, or creates a new one if it doesn’t. It is not necessary to provide any data other than db name while creating database.


> use commandtest
switched to db commandtest

2) Create tables (collection)

Unlike mysql, database tables are called collections in mongodb...

Read More

ERROR 1148 (42000): The used command is not allowed with this MySQL version – LOAD DATA LOCAL INFILE

I was trying to populate a mysql database from contents inside a csv files as follows, when I got the error 🙁


mysql>LOAD DATA LOCAL INFILE ‘/home/abc/public_html/test.csv’ into table test_list;
ERROR 1148 (42000): The used command is not allowed with this MySQL version

To correct it, I did the following.


1) Open my.cnf and added the line “local-infile=1”  under [mysqld] and [mysql]

[mysqld]
local-infile=1

[mysql]
local-infile=1

Save and quit the file.

/etc/init.d/mysql restart

2) Grant file privilege for the user

mysql> grant file on *.* to user@’localhost’;

mysql>  flush privileges;

3) Restart mysql

/etc/rc.d/init.d/mysql restart


Now try load data command again, and yes!!!!! it works 🙂

Read More

The used command is not allowed with this MySQL version – LOAD DATA LOCAL INFILE

This error normally occurs when you run the ‘load data local infile’ command in mysql.

If you are seeing this error in shell, please check this link

If you are seeing this error while running a php script, here are the following things you can test.

I have a php script as follows for testing.


<?php
mysql_connect(“localhost”,”myuser”,”mypass”)or die(mysql_error());
mysql_select_db(“abc_test”) or die(mysql_error());

$query =”LOAD DATA LOCAL INFILE ‘/home/abc/public_html/test.csv’ INTO TABLE abctesting”;
mysql_query($query) or die(mysql_error());

?>

The file ‘test.csv’ contains some random input and if when this script runs, my database abc_test should populate the table abctesting with contents from the file ‘test.csv’

Unfotunately, when I ran this script over browser, I got the following ...

Read More

“WARNING: You are running on a NUMA machine We suggest launching mongod like this to avoid performance problems: ** numactl –interleave=all mongod [other options]

Mongo was working fine in my Ubuntu machine, but whenever I access mongo shell, it will display the following warning.

root@abc:~# mongo
MongoDB shell version: 2.4.5
connecting to: test
Server has startup warnings:
Tue Aug 13 03:47:13.764 [initandlisten]
Tue Aug 13 03:47:13.764 [initandlisten] ** WARNING: You are running on a NUMA machine.
Tue Aug 13 03:47:13.764 [initandlisten] **          We suggest launching mongod like this to avoid performance problems:
Tue Aug 13 03:47:13.764 [initandlisten] **              numactl –interleave=all mongod [other options]
Tue Aug 13 03:47:13.764 [initandlisten]

First I checked, whether my hardware is NUMA(Non-Uniform Access Memory) enabled. I got the following output which said the answer is yes, it is NUMA enabled.

root@abcl# ...

Read More

530 This FTP server is anonymous only. Login failed.

Ever received the following error while connecting to your site via FTP????

# ftp test.com
Connected to test.com.
220 (vsFTPd 2.3.5)
Name (test):
530 This FTP server is anonymous only.
Login failed.
ftp> bye

You can correct this problem by doing the following in the FTP configuration file.

vi /etc/vsftpd.conf

Now, the following lines will be commented, uncomment them.

local_enable=YES    – this lets the local users login via FTP
write_enable=YES   – this lets the users upload files

Save and quit the file.

/etc/init.d/vsftpd restart

Read More

Upcp hanging – Bad archive: CPAN-SQLite-0.203.tar.gz

I had been trying to upgrade my cpanel version with upcp last day.

My current version – 11.34

Targetted version – 11.38

Tried many times, but each time it was stuck after the following error.

[20130801.235456]      [16015] ! Bad archive: CPAN-SQLite-0.203.tar.gz
[20130801.235456]      [16015] ! Failed to unpack CPAN-SQLite-0.203.tar.gz: no directory

Upon searching, I identified the problem is with the SQLite module. So I killed the currently running process, updated sqlite and ran again and hurrayyyy it worked.

ps aux | grep upcp      – will list the upcp processes running

kill -9 pid              – kill that process where pid is the process id listed in the above command output

cpan -i CPAN::SQLite   - install the cpanel sqlite module directly

/scripts/up...

Read More