A tip: sometimes you install stuff from source and library search order makes analyzing which library you are actually using a mess. A useful tool is ldconfig -p
that will print the cache of the dynamic linker for you allowing you to understand which libraries are actually being used.
Altering the character set of a MySQL database
It happens often that I forget to change the default character set of a database to utf8 and so find out late in the development cycle that many of my fields are based on non utf8 character sets (mostly latin1). Then I go in and modify each field in turn using ALTER TABLE [table] MODIFY [field name] [field type] CHARACTER SET [charset]
. After some digging I found the ALTER TABLE $TABLE CONVERT TO CHARSET [charset]
syntax which converted all fields in a table to a certain character set. I looked for a similar syntax to convert the entire database and found ALTER DATABASE
which, unfortunately, only changes the default character set and collation but does not affect the existing tables, fields or data.
So here is a script that repeats ALTER TABLE / CONVERT TO
on each table in your database:
#!/bin/bash
# parameters...
USER='[your db user name]'
PASS='[your db password]'
DB='[your db]'
CHARSET='[character set (utf8?)]'
COLLATION='[collation (utf8_unicode_ci?)]'
# here we go...
QUERY="SELECT table_name FROM information_schema.TABLES WHERE table_schema = '$DB';"
TABLES=$(mysql -u $USER --password=$PASS $DB --batch --skip-column-names --execute="$QUERY")
for TABLE in $TABLES; do
echo "ALTER TABLE $TABLE ......"
mysql -u $USER --password=$PASS $DB -e "ALTER TABLE $TABLE CONVERT TO CHARSET $CHARSET"
#mysql -u $USER --password=$PASS $DB -e "ALTER TABLE $TABLE CONVERT TO CHARSET $CHARSET COLLATE $COLLATION"
done
Switching Java versions on a Debian/Ubuntu system
I recently found some issues with the openjdk Ubuntu/Debian default Java implementation. Specifically I had issues with their web start support (javaws). I found that the Sun implementation of Java did not have such a deficiency and the Sun implementation is available through the regular Ubuntu/Debian package sources. I installed the Sun implementation and wanted to switch the default Java to that version.
So what have I found out ?
When you want to switch to the Sun implementation:
sudo update-java-alternatives --set java-6-sun
When you want to go back to the openjdk implementation:
sudo update-java-alternatives --set java-6-openjdk
Notice that once you do any of the above you leave “auto” mode which means that new installation of Java implementation will not switch your default one. If that is what you want then ok. If not you can return to “auto” mode with:
sudo update-java-alternatives --auto