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.
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.
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
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 | +------------+------------+
If you have installed MySQL on your Mac and forgot your root password, these instructions are for you.
The following code read the contents of a text file
#!/bin/bash filename='links.txt' while read -r line do echo $line done <"$filename"
To read first five lines only
head -5 dinks.txt | while read a; do echo $a; done
Read five lines and then delete those lines
head -5 links.txt | while read a; do echo $a; done sed -i "1,5 d" links.txt
Following code uses DOM to extract links.
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,
You pushed your changes to GIT but you don't see it in the repository.
First thing is to compare status with log
will give you a list of the commits. You will not see your changes here.
You will see your files here. Above the list of files, you will see
Changes to be committed
The reason you don't see your changes in repository is because they were not committed.
If a string contains a single quote, it will generate an error. mysqli->real_escape_string() escapes quotes for MySQL. See example:
Replace multiple spaces with one space
See the following code:
<?php $str = 'This string has many spaces'; $str = preg_replace('/\s+/', ' ', $str); print $str; ?>
This string has many spaces