Archive for category MySQL

Convert MySQL database to UTF-8

To convert MySQL database to UTF-8 encoding, you could use the following shell command:

mysqldump --user=username --password=password --default-character-set=latin1 --skip-set-charset dbname > dump.sql
sed -r 's/latin1/utf8/g' dump.sql > dump_utf.sql
mysql --user=username --password=password --execute="DROP DATABASE dbname; CREATE DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci;"
mysql --user=username --password=password --default-character-set=utf8 dbname < dump_utf.sql

No Comments

Website MySQL Database Slow Fix

Fix for MySQL query slow on your website when post data to your database. You may experience that though the website is up and running, but every time you post data to the MySQL, it becomes slow. This poor performance is caused by lack of optimization.

Your MySQL database might run slowly if it has a lot of “overhead”. Overhead is caused by rows being deleted, leaving empty space. The more active a database is, the more overhead there may be. For instance, when Spam Karma sifts through spam comments in WordPress, it creates and subsequently deletes a lot of rows.

You can cleanup overhead with phpMyAdmin. View the Structure of your database in phpMyAdmin. At the bottom, click “Check tables having overhead”. Then select the pulldown “Optimize Tables”.

You can also cleanup overhead via a shell script and/or cron job. You may want to run a monthly cron job to do this for you. A cron job entry might look like so:

#!/bin/sh
/usr/bin/mysqlcheck -o -v -u USER -pPASSWORD -h MYSQL.YOURDOMAIN.COM DATABASENAME;

Replace the items in all-caps with values appropriate for your site.

No Comments

MySQL Default Schema

If you use MySQL Query Browser, when you launch the application, there is one field asks for Default Schema, to those who are wondering what the heck Default Schema is, it is actually just the default database you want to select once connect to the server.

MySQL Query Browser Launch Screen

MySQL Query Browser Launch Screen

So you can enter any existing database name at your server as the Default Schema, and it’s not a big deal if you choose to leave it blank, you can always select the database at anytime after you connect to the server.

Hope this helps! :)

1 Comment