Posts Tagged ‘WordPress’

Disable WordPress post revision

Saturday, April 4th, 2009

WordPress 2.7 build-in revision feature to save all backup articles (or you may call posts). However, the backup articles almost will not be used and a lot of database storage is wasted. Therefore, I disabled revision feature in my blog. Here is the solution to turn this feature off.

  1. Edit wp-config.php that is saved in WordPress root directory.
  2. Add the following red statement at wp-config.php. It’s suggested to add the red statement at the last 2 line (before ?>).
    ...........
    require_once(ABSPATH . 'wp-settings.php');
    define('WP_POST_REVISIONS', false);
    ?>

If you have wrote many articles previously, I believe your database has already stored many unnecessary articles. To release the storage, it is suggested to remove the existing revision articles.

  1. Go to phpMyAdmin
  2. Click SQL button:
    phpmyadmin_sql
  3. Enter and submit the following SQL statements:
    DELETE FROM wp_posts WHERE post_type = "revision";
  4. Finally, phpMyAdmin will show you how many revision articles have been deleted:
    deleted
  5. If error occurs, you should substitute wp_ to the table prefix of your WordPress

Converting database charset from latin1 to utf8

Sunday, December 14th, 2008

Few months ago, I converted my another blog’s database character set from latin1 to utf8. The following is my conversion steps.

Prepared Software

  • MySQL 4.1 or later
  • Unicode Text Editor (eg. Notepad++)
  • phpMyAdmin (Optional)

 
1. Export the database
I used mysqldump command to export the database to SQL file. I am not sure whether it works with phpMyAdmin. Please let me know if this way works. It is very important to set default-character-set to latin1.
mysqldump -h localhost --user=[username] -p --default-character-set=latin1 --insert-ignore --skip-set-charset [database] > dump.sql

 
2. Replace SQL statements
This procedure is replacing the charset keywords from latin1 to utf8 inside a SQL file, so that the collation of tables will be set to utf8. It is recommended to use Notepad++. If the Chinese characters can be shown in the text editor, it mean you have chosen a correct editor and the previous step is right. The replacing strings are the following:

Find:
DEFAULT CHARSET=latin1
Replace:
DEFAULT CHARSET=utf8
Now you can save it as dump_utf8.sql. And do NOT save it directly (file name:dump.sql) becuase this SQL file is for backup.

 
3. Modify the default Collation
When you create the new tables in the future, new tables will be set to the default character set, latin1. Therefore, it is suggested to modify the default Collation to utf8. You could choose either MySQL monitor or phpMyAdmin to modify and the below example is using MySQL monitor.

Login to MySQL:
mysql --user=[username] -p

After logged in, input the following SQL statement:
ALTER DATABASE [database] DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

 
4. Import the modified SQL file
I also selected MySQL monitor to import the modified SQL file. Please make sure that the default-character-set is utf8 in this time.
mysql --user=[username] -p --default-character-set=utf8 [database]< dump_utf8.sql

 
5. Change web applications configuration
The conversion is basically completed. If you find the text of your web application unable to show correctly, you are needed to change the charset setting. For example:

WordPress (wp-config.php)
define( 'DB_CHARSET', 'utf8');
Discuz (config.inc.php)
$dbcharset = 'utf8';