Der beste Weg eine MySQL Datenbank auf einen neuen Server umzuziehen

Meiner Meinung nach der beste und schnellste Weg eine MySQL Datenbank von Server Alt auf Server Neu zu bekommen ist es, auf Server Alt folgendes Befehl zu starten:

mysqldump –add-drop-table –extended-insert –force –log-error=error.log -uUSER -pPASS OLD_DB_NAME | ssh -C user@newhost „mysql -uUSER -pPASS NEW_DB_NAME“

Das führt dazu, dass die Ausgabe von mysqldump direkt komprimiert und verschlüsselt per SSH auf den neuen Server geschickt wird und dort sofort von mysql verarbeitet wird. Ausgabe gibt es während der Ausführung leider keine…

Eine vorhandene Serendipity Installation von MySQL auf Postgres migrieren

Penny hat ihr vorhandenes Blog von MySQL auf Postgres migriert und die Vorgehensweise dokumentiert. Das ist natürlich ein sehr spezieller Fall, lässt sich aber meiner Meinung nach, auch gut auf andere MySQL-to-Postgres Migrationen anwenden. Mit ihrer Erlaubnis poste ich hier mal ihre Vorgehensweise:

„1. dump the mysql database with some special magic options. I’m not
sure about the encoding part of all this, I assumed the mysql database
was unicode but may have been wrong.

mysqldump –skip-comments \

–complete-insert –default-character-set=UTF8 \

–no-create-info –skip-add-locks –skip-opt \

–compatible=postgresql \

$yourdbname > mysql-pg-compat.sql

2. create a temporary postgres database to work in

createdb -O $someuser -E UTF8 s9ytemp

3. point a test s9y installation at that new database you created and
run through the installation process to get it to install all your schema.

4. make sure at this point you also install all the plugins you want

5. the s9y installation process does put data into those tables, so get
pg_dump to create you just the schema part:

pg_dump -Fc -f pg-schema.sql s9ytemp

6. drop and recreate your temporary postgres database

dropdb s9ytemp
– repeat step 2.

7. restore the schema you just created into your new temp database

pg_restore -s -v -Fc -d s9ytemp pg-schema.sql

8. start munging some stuff in the mysql dump
8a. add transactions around it
echo „BEGIN;“ > mysql-pg-compat-tx.sql
cat mysql-pg-compat.sql >> mysql-pg-compat.sql
echo „COMMIT;“ >> mysql-pg-compat-tx.sql

8b. fix up weird table name sensitivity issue

cat mysql-pg-compat-tx.sql | perl -pe ’s/pluginPath/pluginpath/g‘ >

(you could do this in place with perl -pi -e ’s/pluginPath/pluginpath/g‘
mysql-pg-compat-tx.sql too.

9. Restore the data from the mysql dump into the postgres database
psql -f mysql-pg-compat-tx(-fixed).sql -d s9ytemp

Watch the output.. as soon as you see errors, ctrl-c it and check the
error & fix it. Repeat all necessary steps until this completes with no

This took me about 6 goes to get right, at which point I found a few
instances of 4, and 8b. You might find others 🙂 This is why 8a is
important 🙂

10. Fix up the sequences

Create a file called fixsequencesgen.sql containing:


‚SELECT setval(‚ ||

quote_literal(relname) ||

‚, (SELECT MAX(id) FROM ‚ ||

substring(relname from 1 for octet_length(relname) – 7) ||

‚), true);‘




relkind = ‚S‘ AND

relname like ‚%_id_seq‘ AND

relnamespace IN (






nspname NOT LIKE ‚pg_%‘ AND

nspname != ‚information_schema‘


and then do:

psql -d s9ytemp -f fixsequencesgen.sql -o fixsequencestemp.sql

cat fixsequencestemp.sql | grep SELECT > fixsequences.sql

(again, you could do this in place)

open up fixsequences.sql and change these lines:

– SELECT setval(’s9yauthors_authorid_seq‘, (SELECT MAX(id) FROM
s9yauthors_autho), true);
– SELECT setval(’s9ycategory_categoryid_seq‘, (SELECT MAX(id) FROM
s9ycategory_categor), true);
+ SELECT setval(’s9yauthors_authorid_seq‘, (SELECT MAX(authorid) FROM
s9yauthors), true);
+ SELECT setval(’s9ycategory_categoryid_seq‘, (SELECT MAX(categoryid)
FROM s9ycategory), true);

This is because the above script I stole from another project mysql ->
pg migration I did (moodle) which always uses ‚id‘ as the field name for
the primary key. It could probably be smarter, but changing the two
lines works fine too.

Apply that file to the database:

psql -d s9ytemp -f fixsequences.sql

11. Do a pgdump of your new s9y postgres database:

pg_dump -Fc s9ytemp > s9y.pgdump

12. Copy it to your production server, and do

createdb -E UTF8 $yours9ydbuser s9y
pg_restore -Fc -d s9y s9y.pgdump

13. Switch over your production s9y to use postgres (by editing

14. Done! Go and have something strong to drink!

Other miscellaneous things I found:

– – I couldn’t get the spamblocklog table to create itself .. I ended up
commenting out the if ($versioncomparison) { line above the CREATE TABLE
part in the plugin …

– – Running postgres 8.1 on the computer I was working on and then trying
to restore into a 7.4 production postgres was an unhappy experience that
I don’t recommend. I didn’t realise this until I got to step 12 🙁

In case that happens, try 11 and 12 like:

pg_dump -Fp s9ytemp (rather than Fc) and then you can just do psql -d
s9y < s9y.pgdump"

Auf der Suche nach dem perfekten PHP Application Framework

Ich habe mich in letzter Zeit etwas nach Frameworks für die Applikationsentwicklung in PHP umgesehen. Hintergrund ist die anstehende Entwicklung einer etwas grösseren Anwendung. Das Framework sollte den MVC-Pattern umsetzen, eventuell Hilfestellungen bei Routine-Tasks geben, aktuell sein (weiterentwickelt werden) und vor allem sollte die verfügbare Dokumentation umfangreich sein.

Nach kurzer Zeit musste ich feststellen, dass die Auswahl sehr gross und unübersichtlich ist. Bisher habe ich mich nicht entschieden. Vielleicht hat der eine odere andere Leser Erfahrungen mit einem dieser Frameworks und möchte sie mit mir teilen? Ausserdem mag ich mit diesem Überblick die Leute unterstützen, die vor einer Ähnlichen Entscheidung stehen.

Es handelt sich hierbei wirklich nur um einen Überblick und keine Bewertung. Es werden die mir bekannten Frameworks mit der Beschreibung von ihrer Webseite verlinkt.

(mehr …)

Web Developer command line tricks

“ Below is a list of command line tricks I’ve found to be very useful in web development that a surprising number of web developers don’t know about.

1. ln -s /some/destination name_of_link

This is pretty straightforward: it’ll create a symbolic link from name_of_link to /some/destination. If I’m sitting in /www/matthew/ and I entered the above command, a new file will be created inside that directory that moves the user to /some/destination if they CD to name_of_link. (It’s a shortcut, basically).

If I’m working on a web server where the docroot is buried deep in a directory structure, I’ll often create a symbolic link in something like /www to save myself a few keystrokes when accessing it.

Also, apache won’t follow symbolic links unless you tell it to do so using the following directive: Options +FollowSymLinks
2. tail -f /some/file

This tails a file: it’ll read what’s at the end and output it to your terminal. The -f parameter tells it to keep outputting as the file grows. I use this a lot when examining log files that are constantly being written to.
3. ctrl+z and bg

ctrl+z is the long lost brother of ctrl+c. It’s a signal that tells the process to suspend execution, while ctrl+c terminates it. Ctrl+z is useful if you execute a process but you want to get control of your shell; it’ll suspend the process and send it to the background. Think of ctrl+z like minimizing a window, except once it’s minimized it’s not doing anything anymore. If you want the process to stay in the background but continue running, that’s where bg (background) comes in: typing bg once a process has been suspended makes the process resume but still keeps it in the background.

I often combine ctrl+z and bg with tail:

shell> perl -e ‚while() { print „.“; sleep(1); }‘ > bunch_of_dots.log

[hit ctrl+z, execution is suspended]

shell> bg [process is now in the background and running]
shell>tail -f bunch_of_dots.log [show me the printed dots]

4. fg and jobs

fg is used if you background a process but want to bring it to the foreground. If you have multiple processes in the background, type ‚jobs‘ into your terminal to see them all. This will display a list of processes that are in the background with each process assigned a number (Note: these are not the same as pids). Typing fg [some number] will resume the process you sent to the background where [some number] matches the number reported by ‚jobs.‘

A good example of using fg is if you’re working with an interactive program, such as the mysql command line, but you want to drop back to the shell.

mysql>SELECT foo FROM bar;

mysql> [hit ctrl+z]

[1]+ Stopped

shell>pwd /home/matt/stuff


[1]+ Stopped mysql -u matt -p matts_db

shell>fg 1

mysql>[hooray, we’re back in the mysql command line]

You can omit the job number when running ‚fg,‘ it’ll just foreground the first process you sent to the background. So if you only have one process in the background you can just type ‚fg‘ without any extra numbers.

5. Hit the freakin tab key!

Assuming your shell is configured properly, hitting tab will auto-complete with whatever it thinks you need. I’ve encountered a surprising number of developers who don’t know about this and move around servers at glacial speeds. If you aren’t familiar with the tab auto-complete, get to a terminal right now and type cd [tap the tab key], you should see a list of available files or commands.

6. scp

This securely copies a file across a network using SSH for data transfer. For example:

scp [email protected]:~/secret_stuff /some/destination

This would connect via SSH to as the user ‚matt‘ and copy the file ’secure_stuff‘ from my home directory on to /some/destination on the machine I’m currently on. It’s saved me a ton of time when transferring sensitive files from one machine to another.

Web Developer command line tricks


„Do you hate starting on a new project and having to try to figure out someone else’s idea of a database? Or are you in QA and the developers expect you to understand all the relationships in their schema? If so then this tool’s for you.

SchemaSpy is a Java-based tool that analyzes the metadata of a schema in a database and generates a visual representation of it in a browser-displayable format. It lets you click through the hierarchy of database tables via child and parent table relationships. The browsing through relationships can occur though HTML links and/or though the graphical representation of the relationships. It’s also designed to help resolve the obtuse errors that a database sometimes gives related to failures due to constraints.“