MySQL error: failed to connect to server on ‘xxx.yyy.zzz.aaa’ (113)

Sometimes using MySQL Workbench I am getting this kind of errors:

Failed to Connect to MySQL at xxx.yyy.zzz.aaa:3306 with user db_user
Can’t connect to MySQL server on ‘xxx.yyy.zzz.aaa’ (113)

To fix it add configuration directive:
skip_name_resolve = off
to main MySQL configuration file /etc/my.cnf using your favorite text editor (mine is Vim).
to section [mysqld]
and restart MySQL server using command as root:

# /etc/init.d/mysqld restart

General transfer Magento website procedure in Linux

My general transfer Magento website on Linux procedure

1. Export MySQL database to SQL dump to file using phpMyAdmin or mysql command-line:
mysqldump -h localhost -u db_user -p db_name > ./db_name.sql
…or any other utility.
MySQL database host, name, user and password can be found in file ./app/etc/local.xml

Example section with db settings:
<config>
<global>
<resources>
<db>
<table_prefix><![CDATA[]]></table_prefix>
</db>
<default_setup>
<connection>
<host><![CDATA[localhost]]></host>
<username><![CDATA[db_user]]></username>
<password><![CDATA[db_password]]></password>
<dbname><![CDATA[db_name]]></dbname>
<initStatements><![CDATA[SET NAMES utf8]]></initStatements>
<model><![CDATA[mysql4]]></model>
<type><![CDATA[pdo_mysql]]></type>
<pdoType><![CDATA[]]></pdoType>
<active>1</active>
</connection>
</default_setup>

2. If you transfer Magento from one domain (domain1.com) to another (domain2.com) replace all matches in SQL dump file using vim:

domain1.com
—>
domain2.com

:%s/domain1.com/domain2.com/g
:w

or

http://domain1.com
—>
http://domain2.com

:%s/http:\/\/domain1.com/http:\/\/domain2.com/g
:w

or using Perl, sed or any other utility.
I am prefering to make SHA1 checksum using command:
sha1sum -b ./db_name.sql
and archive it after each replace:
tar cpjf ./db_name.sql-N.tar.bz2 ./db_name.sql
for each saved sql file version.
Do not forget to replace both www. and without www. domain name versions.

3. Make all files backup.
For example:
cd /var/www/vhosts/domain1.com/httpdocs
tar cpjf /var/www/vhosts/domain1.com/private/domain1.com.tar.bz2 ./ –exclude ./var/cache –exclude ./var/reports

4. Copy backup to new server using scp (ssh secure copy):
scp /var/www/vhosts/domain1.com/private/domain1.com.tar.bz2 domain2@domain2.com:/home/domain2/
or lftp (via plain ftp):
lftp -e ‘put -a -O / /var/www/vhosts/domain1.com/private/domain1.com.tar.bz2; bye;’ -u domain2,ftp_password domain2.com
or any other FTP client.

5. Restore files from backup:
cd /home/user2/public_html/
tar xjf /home/user2/domain1.com.tar.bz2 ./
mkidr -pv ./var/cache
mkidr -pv ./var/reports
Make both ./var/cache and ./var/reports writable for web server user e.g. apache or nobody using chmod.

6. Restore MySQL database from file:
mysql -h localhost -u db_user -p db_name < ./db_name.sql 7. Change Magento settings in file ./app/etc/local.xml suitable for new server. 8. Do not forget to check all custom .htaccess rules (custom php_value, rewrite rules, password protection, etc.) to match paths and server configuration at new server. 9. If you go from dev to production do not forget to check ./robots.txt file: User-agent: * Disallow: / --->
User-agent: *
Allow: /
and vise versa.

Do you have any thoughts about this subject?

Linux: how to find files changed in dates range

Working in Linux you need to find files changed in dates range.
To find these files I am using set of commands below:

1. Create file stamp with date range begin:

$ touch –date "2012-11-01" ~/tmp/2012-11-01.txt

2. Create file stamp with date range end:

$ touch –date "2012-11-10" ~/tmp/2012-11-10.txt

3. Find all files in user home directory changed in dates range:

$ find ~ -type f -newer ~/tmp/2012-11-01.txt -not -newer ~/tmp/2012-11-10.txt