mysqlslap to benchmark mysql queries

September 28th, 2009

mysqlslap is worth a look

mysqlslap --host=myhostname --user=myusername -p'mypassword' --create-schema=mydatabase --delimiter=';' --concurrency=10 --iterations=5 --query=/tmp/queriestobenchmark.sql

SAMPLE /tmp/queriestobenchmark.sql file

SELECT * FROM users; SELECT title FROM forum

Find and replace text in all html files using PERL

September 28th, 2009

To find and replace “findme” with “replacewithme” in all HTML files in a directory /var/www/html use

find /var/www/html -name '*.html' -print0 |xargs -0 perl -p -i -e 's/findme/replacewithme/g'

To find and replace “findme” with “replacewithme” in all HTML files in a directory /var/www/html and to backup the original files as let’s say filename.unixtimestamp use

find /var/www/html -name '*.html' -print0 |xargs -0 perl -p -i.`date +%s` -e 's/findme/replacewithme/g'

grep --color=auto

September 28th, 2009

Use --color=auto with grep to highlight the matches

cat somefile | grep --color=auto "findme"

Find some text within files

September 28th, 2009

To find “findme” (case-insensitive) in all html files in /var/www/html directory use

find /var/www/html -name "*.html" -exec grep -i -l "FiNDmE" {} \;

To find “findme” (case-sensitive) in all html files in /var/www/html directory use

find /var/www/html -name "*.html" -exec grep -l "findme" {} \;

Create a copy of a MySQL database on a different server

September 20th, 2009

To create a copy of database mysource on Server A as database mydestination on Server B, I follow these two steps:

1) Create database mydestination on Server B.

CREATE database mydestination

2) Then, run this command

mysqldump -hipaddressofserverA -uusernameofserverA -ppasswordofofserverA mysource | mysql -hipaddressofserverB -uusernameofserverB -ppasswordofserverB -C mydestination

Unblock (open) a port in CentOS

September 20th, 2009

To unblock (open) say port 8000 use:

/sbin/iptables -I INPUT -p tcp --dport 8000 -j ACCEPT