Posts tagged with ‘mysql’

 

This guide aims to go through installation of PEAR modules using XAMPP. The module to install is MDB2.

I use XAMPP Lite instead of the full XAMPP but I imagine it to be the similar. My platform is Windows Vista.

0. Objective

To install PEAR module, MDB2, using a XAMPP set up. Also install the MySQL, MySQLi and PostgreSQL drivers.

1. Setting up environment variables

(more…)

 

Keep getting this today. Looks like tweaking the MySQL and Apache processes didn’t really work. Things still go down. I had to do a hard reboot today:

Out of Memory: Kill process 4446 (mysqld) score 124676 and children.
Out of memory: Killed process 4446 (mysqld).
Out of Memory: Kill process 4712 (mysqld) score 53658 and children.
Out of memory: Killed process 4712 (mysqld).
Out of Memory: Kill process 4727 (mysqld) score 53658 and children.
Out of memory: Killed process 4727 (mysqld).
Out of Memory: Kill process 4728 (mysqld) score 53658 and children.
Out of memory: Killed process 4728 (mysqld).
Out of Memory: Kill process 4626 (apache2) score 41595 and children.
Out of memory: Killed process 4626 (apache2).
Out of Memory: Kill process 4613 (apache2) score 41570 and children.
Out of memory: Killed process 4613 (apache2).
Out of Memory: Kill process 4742 (mysqld) score 104640 and children.
Out of memory: Killed process 4742 (mysqld).
Out of Memory: Kill process 4812 (mysqld) score 70759 and children.
Out of memory: Killed process 4812 (mysqld).

This 256 MB VPS runs 2.5 blogs and 1 Python.

Well, it’s time to upgrade to 512 MB I guess. I was intending to up the lighttpd server but perhaps it shall stay asleep but another 2 months. I probably am upgrading to 512 MB coming January.

 

It was a little sluggish yesterday and I had to do a hard reboot ’cause a soft reboot just hung there. I am running on very limited resources. I have only 256 MB of RAM and every little bit counts. I am on Slicehost by the way.

Previously there wasn’t any problems. It was until recently my friend Daryl have his new blog in my VPS and my new little personal project that’s a little database intensive.

I logged into the web console only to find error messages with MySQL processes. They’re out of memory. I hard rebooted it and tweaked MySQL settings to reduce table caching. Honestly I have no idea what I was doing. People said it worked and I just followed.

That sort of fixed the MySQL problems, but this evening my site become inaccessible again. This time, it was Apache. After reducing the number of Apache servers running, things seem to be doing better.

Here’s my Apache settings, it’s reduced to work on 256 MB RAM:

StartServers 2
MinSpareServers 2
MaxSpareServers 3
MaxClients 70

Then the super cache plugin in WordPress started to misbehave. It just refuse to load anything in the cache after I upgrade super cache. I spent an hour on this one. And I learnt something - when in doubt, just reboot.

 

I’ve been reading about character encoding recently, in particular to the various unicode standards. I’ve been rather pissed off with setting up the wrong collation in MySQL, I just realized that at my other blog, I have posts that are in utf8_unicode_ci, latin1_general_ci and utf_general_ci. This is what you get when you migrate database blindly without knowing what is character set. I regret not reading enough. Now I set everything to utf8_general_ci.

Anyway, something about another encoding set - GB2312 - caught my attention.

Here’s a trivia, the older Chinese encoding GB2312 cannot write the former Chinese Premier Zhu Rongji’s name. His name has often appeared as 朱熔基. Zhu disapproves of this and prefers the correct version, 朱镕基. (more…)

 

Here is how you can do a quick replace of a particular word in your WordPress blog:

UPDATE `wp_posts` SET `post_content` = REPLACE(`post_content`,‘color’, ‘colour’);

This replaces posts with the word ‘color’ and change it into ‘colour’. I was doing a whole lot of string replacements to replace URLs that are no longer valid.

 

One of the easier ways to retrieve data from MySQL by month and year is to use one of MySQL’s built-in functions - MONTH() and YEAR(). The following is a piece of CakePHP code.

function p_month($year, $month) {
  $posts = $this->paginate(
    ‘Post’,
    "status=’approved’ AND MONTH(pub_date)=$month AND YEAR(pub_date)=$year"
  );
  $this->set(compact(‘posts’));
}

If you don’t use CakePHP, a SELECT statement in MySQL would be:

SELECT * FROM `Post` WHERE `Post`.`status`=‘approved’ AND MONTH(`Post`.`pub_date`)=2 AND YEAR(`Post`.`pub_date`)=2008;

The above extracts February 2008 data. Pretty neat.

Previous I wrote crap like:

SELECT * FROM `Post` WHERE `Post`.`status`=‘approved’ AND `Post`.`pub_date`>=‘2008-02-01′ AND `Post`.`pub_date`<‘2008-03-01′;

It’s just messy and ugly. And lots of calculation have to be done before hand.

Hope it helps. I haven’t really tested the SQL statements by the way. But it should work correctly. Only tested the CakePHP code. I use CakePHP 1.2’s paginate function.

 

Don’t know if any one would find this useful. I didn’t like cased tags and I just decide that lowercase is the way to go. I know you can do it with CSS but that’s not the result I want.

UPDATE `wp_terms` SET name=LOWER(name);

I had many tags are some are in capitals, some are in small letters, it looks really messy from my admin panel so I decided to clean of every thing. (more…)

 

WordPress powered and Django inspired.
Love and elephants come after.
RSS: Posts and comments.