Archive for September, 2007

Change charset for all tables.

A lot of linux distributions comes with mysql with default charset latin1. In modern world it seems to be rudimentary, for i18n utf8 is a must. So converting existing mysql databases/tables to utf8 is not an uncommon task. There’s no problem with it, mysql has ALTER TABLE SET CHARSET statement. But what if you have several dozens of tables? And what if each table has a lot of text fields? You’ll spend a lot of time in front of mysql console or phpmyadmin. Or you’ll have to generate script from table/field names.
I offer simple solution when all your data is english (I can’t predict behaviour if you have other data).

  1. Make mysqldump of your entire database
  2. Change all charset definitions sed -i 's/latin1/utf8/' dumpfile.sql
  3. Load dump back to database

Monday, September 24th, 2007

Recursive ftp upload/download

Today we have to upload the whole directory tree to our site. How we can do it? If you use regular ftp command, this task becomes tedious and exhaustive job. You have to recreate each directory, change to each directory locally and remotely and perform mput or mget. If you have complex directory structure it is almost impossible to do that without a mistake. Solution? – Use lftp instead. It has mirror feature which allows to copy entire directory tree. To upload, use -R switch.

Wednesday, September 12th, 2007