Home » Archive

Articles in the MySQL Category

debian, MySQL »

[28 Oct 2011 | One Comment | 704 views]

I completed an upgrade of Debian Lenny to Squeeze on a production database server over the weekend. It went quite well and I had zero downtime thanks to my secondary database servers running in-place. One of the biggest benefits to running Squeeze is that MySQL runs at version 5.1.49. Lenny only supports up to MySQL 5.0.

Row-based-replication is safer to replicate data to other servers since all changes are replicated. Prior to MySQL 5.1.14, updates to the mySQL database were not replicated. They were updated via statements (e.g. GRANT, REVOKE). This can potentially cause data-consistency between the master and …

MySQL, PHP »

[10 Jan 2011 | One Comment | 1,724 views]

If you ever have the need to find the answer to the following:

  • What are the number of tables in a MySQL database?
  • What are the number of rows in a MySQL database?
  • How much space is the MySQL database using up on the server?
  • How many tables there are in a MySQL server?
  • How many rows there are in a MySQL server?

One of the quickest ways to find out MySQL reporting stats is using PHPMyAdmin. The software is usually installed on a number of servers by default, so its just a matter of locating where in the program to find this info.

This is an example of what the stats look …

debian, Linux, MySQL »

[7 Jul 2010 | No Comment | 3,745 views]

The quickest way to disable autostart of services in Debian is to utilize a convenient curses interface to selectively choose which services to autostart in different run levels. Its so much easier to use than update-rc.d.  Its good for instances where you are migrating services out of an existing box, such as removing the mysql server without uninstalling.

The package is called:
sysv-rc-conf

(Install it using aptitude or apt-get install)

MySQL, PHP »

[12 Apr 2010 | No Comment | 1,672 views]

The error message looked like:
“Illegal mix of collations (latin1_swedish_ci,COERCIBLE) and (utf8_general_ci,IMPLICIT) for operation ‘find_in_set’”

I ran into this problem today while importing text from a CSV file. Evidently, the text format of the document had UTF characters, which caused CodeIgniter to error out when it tried to insert it to the database. The line had French characters (The ç in Français) My database fields by default are set to “latin1_swedish_ci” character set.

The fix?
I decided the best way to fix this was to set the Collation option for that specific field in the MySQL database to  “utf8_general_ci

MySQL »

[3 Mar 2010 | 5 Comments | 4,278 views]

MySQL by default will make the ORDER BY option in queries case sensitive. This means that rows with the same starting letters (but different case) may be ordered non-alphabetically. There are three solutions to this. One is to force all database entries to be forced to upper-case or lower-case when inserting. Another is to use the collate option. The other solution is to change the query itself.

MySQL »

[5 Jan 2010 | 2 Comments | 3,948 views]

Here’s the quickest way to sort data in MySQL after retrieving the last 10 entries with the LIMIT and ORDER BY DESC commands. If you simply do a ORDER BY DESC LIMIT 10, this will return the last 10 results in reverse order (newest first). Adding an inline SELECT command will sort the results after retrieving the last 10 items. (oldest first)

SQL Command

$sql = "SELECT * FROM (SELECT * FROM [TABLE] WHERE ORDER BY modified_date DESC LIMIT 10) AS tbl ORDER BY tbl.modified_date"

This will retrieve the last 10 rows while sorting by date chronologically. I used this SQL command for …

MySQL »

[17 Jul 2009 | 3 Comments | 4,642 views]

If your site experiences the infamous “Mysql : Too many connections” error, you will need to tune your MySQL server to handle the load of a heavily used website.

There are some configuration variables that you can adjust to make your site handle more connections.
The wait_timeout default in MySQL is 28840 seconds (8 hours), which can seriously limit the number of open connections you have on your page. I adjusted mine to 60 seconds. This frees up the thread after idle timeout, which allows for more connections to connect. The 8 hour timeframe is fine if you only have a few connections to the server. For popular websites, its best to make this value as low as possible. Set this variable to the maximum time your page typically runs. For instance, if you have a page that needs to retrieve some data processed from another server (60-80 seconds) and you only use one mysql_connect, you may lose the mysql connection for processing the remaining parts of the page if your wait_timeout is too low. If the processing takes much longer, a workaround is to use multiple mysql_connects to prevent an idle connection from disconnecting.

MySQL, PHP »

[11 Jun 2009 | 2 Comments | 869 views]

I’ve been working on tuning my Apache/MySQL/PHP configuration lately to see how to improve the performance. Lately, I’ve been noticing some crawlers that have been ignoring my robots.txt file and hitting my server really hard with several page requests every second. So, I decided to run some tests to see where I could speed up my website in the code.

MySQL, PHP »

[17 Mar 2009 | 7 Comments | 11,417 views]

WordPress introduced a new version of its multi-user blog software in January 2009. I have been using version 2.6 for the past few months and it was working well, although the site management was very confusing to use. Version 2.7 fixes this problem by making the Site Admin menu more uniform with the main dashboard.

MySQL, PHP »

[12 Mar 2009 | One Comment | 1,234 views]

A good practice is to check input strings to make sure users don’t put in mySQL commands in your server. For instance, if a username or password POST variable isn’t filtered, there is a potential for an injection like ‘OR myusername=’. In the past, I’ve been using my own PHP toolkit to “clean” the input variables. But recently, I began searching to see if there are a built-in solution in PHP for this, especially since I’m converting a script written in Python that had the filter MySQLdb.escape_string. Enter mysql_real_escape_string()