Tuesday, January 23, 2007

Linux Shell

Linux Shell

List Files and Directories without Color Coding

$ls --color=none -all


List Files with Auto-Refresh

while [ 1 ]; do clear; ls -allh; sleep 5; done


Generate and Check MD5

$md5sum FILE > md5sum.txt
$md5sum -c md5.txt

Generate the Date of the Form: January_01_YYYY.$ext

$NOW=`date +%B_%d_%a_%Y


Get the Total Size of a Directory and File

$du -hcs dir/dir
$du -h file.tar.gz


Search for Text Pattern in Files

$egrep "stuff.php" *

Split and Join Files

Split and Join Files

$split -b 450m file.tar.gz

With Prefix
$split -b 450m file.tar.gz PREFIX

Join Files
$cat xaa xab xac >> file.tar.gz

Split and Join Files

Friday, January 19, 2007

mysqldump: Couldn't execute SHOW TRIGGERS LIKE

mysqldump: Couldn't execute SHOW TRIGGERS LIKE

Importing a database with 251+ tables on Windows XP results in the following error:
mysqldump: Couldn't execute 'SHOW TRIGGERS LIKE table_name. Can't create
ate/write to file '\tmp\#sql_8d4_0.MYD' (Errcode: 17) (1)

This issue is due to the windows file handles.

[quote]
Please examine the server status variable "open_files_limit" and note that
mysqld requires two open files for each myisam table.

On my machine it looks like this:
mysql> SHOW VARIABLES LIKE 'Open_files_limit';
Variable_name Value
open_files_limit 1024

From the manual:
The number of files that the operating system allows mysqld to open. This is
the real value allowed by the system and might be different from the value you
gave using the --open-files-limit option to mysqld or mysqld_safe. The value is
0 on systems where MySQL can't change the number of open files.

When mysqldump tries to dump the files, it will first take a read lock on all
the tables in the database. That requires it to open all of them at the same
time. So if the number of available open files is low, this kind of error can
occur.

To make mysqldump avoid taking the read lock use --skip-lock-tables option. I
successfully used that to dump more tables than my system had file descriptors.

It should also be possible to put a smaller number of tables in each database or
only dump a selected number of tables at a time.

But that are workarounds, best thing is to increase the number of open files on
the system.
[/quote]

Source:
http://bugs.mysql.com/bug.php?id=17089


mysqldump: Couldn't execute SHOW TRIGGERS LIKE

Wednesday, January 17, 2007

CSV Invalid Field When Importing Into MySQL

CSV Invalid Field When Importing Into MySQL

Check that there are no funny characters such as single quotes or double quotes.
The import fields need to be specified correctly.
The CSV input file needs to be saved in the CSV format.


CSV Invalid Field When Importing Into MySQL

Tuesday, January 16, 2007

Restore a MySQL Database

Restore a MySQL Database

Through Shell:

$ mysql -uUserName -pPassword -hlocalhost DatabaseName < mysql_db.sql


Restore a MySQL Database

Backup a MySQL Database

Backup a MySQL Database

Through Shell:

Backup an entire database

$mysqldump -udatabase_user -p --host="host.com" --opt -f database_name > database_backup.sql

Backup through Windows:

c:\> mysqldump -udatabase_user -p --host="host.com" --skip-lock-tables database_name > database_backup.sql


Backup a table

$mysqldump -udatabase_user -p --host="host.com" --opt -f database_name table_name > database_table_backup.sql

-p prompts for a password after the above command is executed

--force, -f

Continue even if an SQL error occurs during a table dump.

One use for this option is to cause mysqldump to continue executing even when it encounters a view that has become invalid because the defintion refers to a table that has been dropped. Without --force, mysqldump exits with an error message. With --force, mysqldump prints the error message, but it also writes a SQL comment containing the view definition to the dump output and continues executing.

--opt

This option is shorthand; it is the same as specifying --add-drop-table --add-locks --create-options --disable-keys --extended-insert --lock-tables --quick --set-charset. It should give you a fast dump operation and produce a dump file that can be reloaded into a MySQL server quickly.

The --opt option is enabled by default. Use --skip-opt to disable it. See the discussion at the beginning of this section for information about selectively enabling or disabling certain of the options affected by --opt.

Backup a MySQL Database

Saturday, January 06, 2007

Places to Visit

Places to Visit

India:
Taj Mahal, Red Fort Delhi - Visited - 2006

Basilica Old Goa - UNESCO - Visited

Australia:
Sydney Opera House
http://en.wikipedia.org/wiki/Sydney_Opera_House

Australia Zoo

Egypt:
Egyptian Pyramids
http://en.wikipedia.org/wiki/Egyptian_pyramids


Germany:
Magdeburg Water Bridge
http://en.wikipedia.org/wiki/Magdeburg_Water_Bridge

Autobahn
http://en.wikipedia.org/wiki/Autobahn

France:
Eiffel Tower
http://en.wikipedia.org/wiki/Eiffel_Tower

USA:
Niagara Falls
http://en.wikipedia.org/wiki/Niagara_Falls

Hollywood
http://en.wikipedia.org/wiki/Hollywood

Disneyland
http://en.wikipedia.org/wiki/Disneyland

Places to Visit

Find and Replace a Matching String of Text

Find and Replace a Matching String of Text

This script will find all .html files (in the current directory and all subdirectories) and replace the string of text 123 with 456

#!/bin/bsh

for file in $(find . -type f -name '*.html')

do

cat $file |sed "s|123|456|g" > $file.new

mv -v $file.new $file

done

Prefix and escape double quotes with a backslash, (double quotes are used by SED)

#!/bin/bsh

for file in $(find . -type f -name '*.php')

do
cat $file |sed "s|include \"file.php\";|require_once (\'/path/file.php\');|g" > $file.new

mv -v $file.new $file
done


Find and Replace a Matching String of Text

Archive and Compress a Directory

Archive, ZIP/Unzip and Compress/Decompress a Directory

$ tar -zcvf archive.tar.gz sourcedirectory/

Exclude a directory(s) from the archive:

$ tar -zcvf archive.tar.gz sourcedirectory/ --exclude=exclude01-dir/* --exclude=exclude02-dir/subdir/*


ZIP

$ zip db.zip foo-file

$ zip -r dir.zip directory/

Extract contents of a GZ archive
$ gunzip archive.sql.gz

or

$ gzip -d archive.sql.gz


Extract contents of a TAR GZ Archive
$ tar -zxvf archive.tar.gz

Recursively Copy a Directory

Recursively Copy a Directory

cp -r source newdestination

Note: newdestination does not need to exist

Recursively Copy a Directory