Debugging web pages using MySQL

Tags:

mysql> <span style="text-decoration: underline;">show variables like '%log%';
</span>+-------------------------------------+---------------------------------+
| Variable_name                       | Value                           |
+-------------------------------------+---------------------------------+
| back_log                            | 50                              |
...
| general_log                         | OFF                             |
| general_log_file                    | /var/run/mysqld/mysqld.log      |
...
| log                                 | OFF                             |
| log_bin                             | OFF                             |
...
| log_error                           | /var/log/mysqld.log             |
| log_output                          | FILE                            |
...
| slow_query_log                      | OFF                             |
| slow_query_log_file                 | /var/run/mysqld/mysqld-slow.log |
| sql_log_bin                         | ON                              |
| sql_log_off                         | OFF                             |
| sql_log_update                      | ON                              |
| sync_binlog                         | 0                               |
+-------------------------------------+---------------------------------+
40 rows in set (0.00 sec)

mysql> <span style="text-decoration: underline;">SET GLOBAL general_log = 'ON';</span>
^Z
$ <span style="text-decoration: underline;">sudo less /var/run/mysqld/mysqld.log</span>
... (log entries scroll) ...
$ <span style="text-decoration: underline;">fg</span>
mysql> <span style="text-decoration: underline;">SET GLOBAL general_log = 'OFF';</span>
mysql> QUIT;
$

Supporting multiple Wordpress installs

Tags:

Here's a little Perl script that uses some modules off CPAN to :

Rename the .pl.txt file to .pl, chmod a+x so you can run it, and then:

# <span style="text-decoration: underline;">./show_wp_versions.pl</span>

which would display, for example,

Domain                         Version    Tracking Subversion  Owner
-----------                    --------   -------------------  -----
alphabetcompany.com             2.8       tags/2.8             alphabet
awkwardaardvark.com             2.7.1     tags/2.7.1           aardvark
brilliant-doorstops.co.uk       2.3                            dumbasapost

-n sorts by numeric version number; -u sorts alpha by UID.

Very handy when you're supporting a large number of Wordpress installs on a single server, to know who's running what, and who needs to be updated!

NOTE: To install on a fresh system, you will probably need to:

# <span style="text-decoration: underline;">cpan</span>
cpan[3]> <span style="text-decoration: underline;">install App::Info::HTTPD::Apache</span>
cpan[1]> <span style="text-decoration: underline;">install SVN::Class::Info</span>
cpan[2]> <span style="text-decoration: underline;">install Apache::ConfigParser</span>

Export only a Subset of Wordpress pages

Tags:

In the process of splitting one existing Wordpress site (comprised mostly of hierarchically arranged Pages, not posts) I needed to export a batch of pages into the new one. Here's how to modify your wp-admin/includes/export.php to do that.

First we find the ID number of the parent page that we want to export. This process will export that page and all its sub-pages (children), sub-sub-pages, etc. You can find this by hovering over the "Edit" link in the Wordpress "Pages/Edit" area and noting the "&post=number" section. In my case it was "2" -- that's the number we will use below.

In wp-admin/includes/export.php, find the lines:

// grab a snapshot of post IDs, just in case it changes during the export
$post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");

Comment that out, and replace with:

# Export only a particular page and all its children
$post_ids = array();
$new_pages = array();
$new_pages[] = 2; # Parent page ID, which we will export, along with all its children
while (count($new_pages)) {
  $where = "WHERE post_parent IN (".join(',', $new_pages).")";
  foreach ($new_pages as $np) {
    $post_ids[] = $np;
  }
  $new_pages = array();
  $new_pages = $wpdb->get_col("SELECT ID FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");
}
# $post_ids array now contains the pages we wish to export

Simply run the Export process and you will have just those pages.