Copying a large database from one server to another

Recently, I had to copy a large database from one server to another. I had 100G free on the source server. Unfortunately, the server would run out of memory before the mysqldump would complete. So I had to find a way to make the mysqldumps smaller. This can be done by creating separate dumps for each table. Then I had to compress the files to conserve memory. Following is the script I wrote to accomplish this.

split command

In Linux you can use split and join commands to split large files into smaller files or join many smaller files into a large file. This kind of operations are often necessary when you are dealing with large quantities of data.

split

Following is the default functionality of split. It splits a large file every thousand lines and creates new files.

$ split largefile.txt

$ ls
largefile.txt  xaa xab  xac  xad

$ wc -l *
3285  largefile.txt
1000  xaa
1000  xab
1000  xac

You can also define the number of lines you want in each file

Listing all tables and their table counts in a MySQL database

The Following SQL query will list all tables in a MySQL database and also list the row counts for each.

SELECT TABLE_NAME, TABLE_ROWS 
FROM `information_schema`.`tables` 
WHERE `table_schema` = 'mydatabase';

where mydatabase is the name or your database. The output will like something like the following:

+------------+------------+
| table_name | table_rows |
+------------+------------+
| lines      |       2271 |
| links      |        484 |
| word       |      25004 |
+------------+------------+

Perl Quotes and Escape Sequences

Perl string literals are enclosed in quotation marks. You can use either single quotes ('') or double quotes ("").

print "hello";
print 'hello'; 

Now suppose you need to print a string which contains a single or double quote such as following strings:

This is bob's watch.
Alice replied, "It was a birthday gift."

If I do the following,

Pushed changes to GIT but don't see it in repository

Problem

You pushed your changes to GIT but you don't see it in the repository.

Diagnosis

First thing is to compare status with log

git log

will give you a list of the commits. You will not see your changes here.

git status

You will see your files here. Above the list of files, you will see

Changes to be committed

Cause

The reason you don't see your changes in repository is because they were not committed.

Pages