if you want something done right… DIY.

meanderings of a computer scientist on the brink of sheer insanity.

a number of articles and blog posts exist that (attempt to) explain how one might go about connecting to a remote mysql server by way of an ssh tunnel… a vast majority of them are a copy-and-paste of the same information on how to do it using PuTTY as go-between.

seeing as how PuTTY serves the WIntel folks, and i prefer my powerbook to my thinkpad these days, i searched for a solution to do this simply on OS X… and found mention, but not working example, of using Terminal to handle the necessary port forwarding.

i looked more carefully at the man pages for ssh, and lo and behold, the -L option will do everything you need.

launch Terminal and issue this command:

ssh [host] -l [username] -p [port] -L 127.0.0.1:3306:[mysql_server]:[mysql_port] -N

[host], [username] and [port] pertain to the login credentials for the ssh connection (the port will usually but not always be 22)… the -L option is to establish forwarding the standard mysql port (3306) from your own computer (127.0.0.1 aka localhost) to the remote mysql server (usually but not always localhost)… -N tells Terminal to make the connection but provide no interaction, so the console will just sit there without giving you a command shell on the remote machine.

with the tunnel and port forwarding established, you can use MySQL Query Browser or another front-end to connect to 127.0.0.1 on port 3306 and you’ll be on your merry way administering rows of data…

* it should go without saying that this won’t work if you are already running an instance of mysql server on your own machine on port 3306.

in httpd.conf, put this somewhere after LoadModule mod_ssl:

SSLCipherSuite ALL:!ADH:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL

and this declaration in each VirtualHost’s Directory:

SSLRequire %{SSL_CIPHER_USEKEYSIZE} >= 128

in case you have ever wondered when and how it all began…

memex

All this is conventional, except for the projection forward of present-day mechanisms and gadgetry. It affords an immediate step, however, to associative indexing, the basic idea of which is a provision whereby any item may be caused at will to select immediately and automatically another. This is the essential feature of the memex. The process of tying two items together is the important thing.
– Vannevar Bush, “As We May Think” (Atlantic Monthly, 1945)

hypertext

Let me introduce the word hypertext to mean a body of written or pictorial material interconnected in such a complex way that it could not conveniently be presented or represented on paper. It may contain summaries, or maps of its contents and their interrelations; it may contain annotations, additions and footnotes from scholars who have examined it. Let me suggest that such an object and system, properly designed and administered, could have great potential for education, increasing the student’s range of choices, his sense of freedom, his motivation, and his intellectual grasp. Such a system could grow indefinitely, gradually including more and more of the world’s written knowledge.
– T. H. Nelson, “A File Structure for The Complex, The Changing and the Indeterminate” (20th national conference of the ACM, 1965)

tcp

The TCP is responsible for regulating the flow of internetwork packets to and from the processes it serves, as a way of preventing its host from becoming saturated or overloaded with traffic. The TCP is also responsible for retransmitting unacknowledged packets, and for detecting duplicates. A consequence of this error detection/retransmission scheme is that the order of letters received on a given connection is also maintained…
– Vinton Cerf, Request for Comments #675 (1974)

TCP is based on concepts first described by Cerf and Kahn
Request for Comments #793 (1981)

ip

This document specifies the DoD Standard Internet Protocol. This document is based on six earlier editions of the ARPA Internet Protocol Specification, and the present text draws heavily from them. There have been many contributors to this work both in terms of concepts and in terms of text. This edition revises aspects of addressing, error handling, option codes, and the security, precedence, compartments, and handling restriction features of the internet protocol.
– Jon Postel, Editor, Request for Comments #791 (DARPA, 1981)

www

One of the things computers have not done for an organization is to be able to store random associations between disparate things, although this is something the brain has always done relatively well. In 1980 I played with programs to store information with random links, and in 1989, while working at the European Particle Physics Laboratory, I proposed that a global hypertext space be created in which any network-accessible information could be refered to by a single “Universal Document Identifier”. Given the go-ahead to experiment by my boss, Mike Sendall, I wrote in 1990 a program called “WorldWideWeb”, a point and click hypertext editor which ran on the “NeXT” machine. This, together with the first Web server, I released to the High Energy Physics community at first, and to the hypertext and NeXT communities in the summer of 1991. Also available was a “line mode” browser by student Nicola Pellow, which could be run on almost any computer. The specifications of UDIs (now URIs), HyperText Markup Language (HTML) and HyperText Transfer Protocol (HTTP) published on the first server in order to promote wide adoption and discussion.
– Sir Tim Berners-Lee, “The World Wide Web: A very short personal history

although “the web” has no one physical container, the first web server, Tim’s NeXT machine, is quite tangible:

and here’s the first web client:

incidentally, Ted Nelson considers the web to be a largely inadequate realization of hypertext/hypermedia:

The Web is the minimal concession to hypertext that a sequence-and-hierarchy chauvinist could possibly make.

this is not actually surprising, as he has been working on something far more ambitious since the early 1960’s.

debugging gallery2 after upgrade

no idea what version to which this applies as i’ve never installed or configured gallery2, but here’s the process by which i just now debugged one particular gallery2 install…

gallery2/config.php

line 30 - @ini_set(’display_errors’, 1);
line 134 - $gallery->setDebug(’buffered’);

1st error:
Unknown column ‘g2_Item.g_renderer’

grep -r ‘renderer’ *

modules/core/classes/GalleryStorage/schema.tpl:

CREATE TABLE DB_TABLE_PREFIXItem(

DB_COLUMN_PREFIXownerId int(11) NOT NULL,
DB_COLUMN_PREFIXrenderer varchar(128),

ALTER TABLE g2_Item ADD g_renderer VARCHAR(128) NULL AFTER g_ownerId;

2nd error:
Unknown column ‘g2_Comment.g_author’

grep -r ‘PREFIXauthor’ *

modules/comment/classes/GalleryStorage/schema.tpl:

CREATE TABLE DB_TABLE_PREFIXComment(

DB_COLUMN_PREFIXdate int(11) NOT NULL,
DB_COLUMN_PREFIXauthor varchar(128),

ALTER TABLE g2_Comment ADD g_author VARCHAR(128) NULL AFTER g_date;

perhaps this may help someone else out there.

beware of table alias in LEFT JOIN

when mixing standard selects containing table aliases with LEFT JOIN’s you need be aware of a critical change as of mysql 5… if you reference a table alias in an ON clause the same way you might have in verison 4, mysql may report an ‘unknown column’ error.

so, a query of the form:

SELECT a.id FROM alpha a, beta b
LEFT JOIN gamma g ON (g.id = a.gamma_id)
WHERE b.id = a.beta_id

would report error #1054 - Unknown column ‘a.gamma_id’ in ‘on clause’

whereas:

SELECT a.id FROM (alpha a, beta b)
LEFT JOIN gamma g ON (g.id = a.gamma_id)
WHERE b.id = a.beta_id

… would not.

in case you failed to detect the subtle difference between the two, it’s the inclusion of the now-apparently-very-important parentheses around the list of tables before the LEFT JOIN.

this ‘bug’ has been reported to mysql ab (even though they claim is not a bug).

if you’ve divorced movabletype, successfully exported and imported your existing posts, and eloped with wordpress, undoubtedly you’ll want to maintain all the inbound links google and other search engines have accumulated over time so that your adoring public will still be able to locate your scribblings…

here are the three most important classes of url’s to preserve:

1. category

MT — /archives/{category_name}
WP — /category/{category-name}

2. monthly archive

MT — /archives/{year}/{month}/
WP — /{year}/{month}/

3. post

MT — /archives/{year}/{month}/{slug}.html
WP — /{year}/{month}/{day}/{slug}/

you’ll note that none of the wordpress url’s contain the archives/ prefix. you can use this to your advantage in the url rewrite rule you’ll define in your .htaccess file.

RewriteRule ^archives/(.*) mt-wp.php?$1

in the above example, everything after archives/ in the incoming url will be passed to a php script called mt-wp.php which will do the work of determining which of the above three url classes it is, reformatting the url to the appropriate one used by wordpress, and either redirecting to that url or serving it up by proxy.

for [1] you will merely replace underscores with dashes. for [2] you will use the query string as-is. [3] is slightly trickier and is the reason why you’ll handle redirection (or proxy, using a socket connection or the cURL library) in a [insert language du jour here] script instead of a set of three RewriteRule’s.

movabletype’s post slugs are more brief than the ones wordpress generates, and, whereas movabletype does not include the full date of the post in its url, wordpress does.

unless you were in the habit of writing a slew of posts any given month with utterly similar headlines, it should be sufficient to use just the first two words from movabletype’s slug, in addition to the month and year, as keys to locating that post in your wordpress database. break up the slug portion of the url into words using the underscore as your delimiter, and concatenate the first two words together with a dash: word1_word2_word3 becomes word1-word2.

now, query:

SELECT guid FROM wp_1_posts
WHERE post_name LIKE ‘{word1}-{word2}%’
AND post_date LIKE ‘{year}-{month}%’

i find it wonderfully convenient, especially for the purposes of this exercise, that wordpress provides the full url to the post in the guid column.

*substitute wp_1_posts for the table containing the posts you’ve imported from movabletype.

if you’ve been following so far, generating code in your language of choice to do all of this should be a walk in the park. i leave it to you…

dear microsoft,

in response to this update about the ‘css improvements’ in IE8, and my previous post about your brilliant ‘version targeting’ concept, i have the following recommendation:

GIVE UP.

what a sordid history “your” browser has endured!
it is time you sent it off on an ice floe.

WTFs/minute

say what?

‘The proposed default behavior for version targeting in Internet Explorer solves the problem of “breaking the web” in much the same way that decapitation solves the problem of headaches.’

README

if, after painfully specifying character set and collation for your database, all your tables, and all columns within them, you’re still experiencing discrepencies between what your database is storing (eg. strings appear correct from within phpMyAdmin) versus what your website is displaying from database query results (question marks instead of your fancy quotes), try this:

mysql_query(”SET character_set_client = utf8;”);
mysql_query(”SET character_set_results = utf8;”);

those two lines should go right after your mysql_connect() and mysql_select_db().

after several hours of trial-and-error i arrived at the above solution as if by magick. here’s hoping it helps someone else…

« Previous Entries