BitterSweetJaVa

May 6, 2009

MySQL, change column encoding

Filed under: MySQL — Tags: , — .|2ic|K @ 10:41 PM

I was having a problem when using characters with accents in a web application. After spending some time investigating the issue, I found out that the problem was in the default encoding applied by MySQL in the tables. I solved the issue using the following command to change the encoding of the desired column (I’ll convert the entire DB in the future):

UPDATE [Table] SET [column] = CONVERT(CONVERT(CONVERT([column] USING latin1) USING binary) USING utf8);

Note that It converts the data first from latin1 to binary and then from binary to utf8.

Now the web application is showing the appropriate characters.

March 6, 2009

MySql Database Backup & E-Mail (2)

Filed under: Linux, MySQL, SQL — Tags: , , , — .|2ic|K @ 6:33 PM

Well, now that we have the email script working (at least it Worked for me), let’s create a job using cron to execute it on a regular basis.

First of all, I created a new cron file under /etc/cron.d/ called dbBackup.
The file contains a simple cron expression:

0 20 * * 5 root /etc/init.d/dbBackup &

Basically, this will:

  • Execute the command /etc/init.d/dbBackup
  • The execution will be as a background process (&)
  • The schedule will be every friday at 8:00pm
  • The user that will execute it will be root.
  • In this case, /etc/init.d/dbBackup is the script that I posted previously to make a backup of the MySql database.
    I’ve just received the first scheduled email an hour ago!

    For more info on cron syntax, you can visit this site.

    Theme: Shocking Blue Green. Blog at WordPress.com.

    Follow

    Get every new post delivered to your Inbox.