Tiny Tiny RSS / MySQL: Problems with UTF8 Emojis

Since Google shut down its Reader service, I am a regular user of the Tiny Tiny RSS reader. Having my own RSS reader installation gives me more power regarding my privacy and the services I am using. Consider me a happy user.

However, there are some issued regarding full UTF8 support when using MySQL. When a feed uses UTF8 emoijs, tt-rss will throw up and report an error. Unfortunately, this only manifests itself with log entries like this:

Read the rest of this entry »

MySQL: Return random row

For habere.ch, we launched a contest where we award a restaurant voucher to a random person that wrote a review of a restaurant on our site. For this, we will be using the following query:

SELECT DISTINCT comment_author,comment_author_email
FROM wp_comments
ORDER BY RAND()
LIMIT 1;

What this query does is, that it selects all distinct rows, orders them randomly and shows the first entry of this selection.

Note that this query is relatively slow and should not be used in a program. When you use EXPLAIN on this query, MySQL will explain to you that it will create a temporary table and run a sort. Then only one entry is returned. But when you just use it once to determine a winner, this will work just fine!

MySQL: Import from CSV

Today I had to import some data from a CSV file into a table on a MySQL server.
So here is how to do it:

LOAD DATA LOCAL INFILE '/importfile.csv' 
INTO TABLE test_table 
FIELDS TERMINATED BY ',' 
LINES TERMINATED BY '\n' 
(field1, filed2, field3);

Source

Of course, you will need to have access to the machine where the database is running. As an alternative, I am sure there are developer tools that can enter the data remotely.

WordPress MySQL Permissions

Having security in mind, I had some concerns granting all privileges to the WordPress MySQL user (see the instructions from WordPress):

GRANT ALL PRIVILEGES ON databasename.* TO "wordpressusername" [..]

After all, with these privileges the WordPress user would be able to access other databases on this server and do whatever he likes. WordPress has become very popular and is a known target for exploits and the like (as a quick search on milw0rm.com will confirm). I didn’t like that idea.

So here is what I did:

GRANT SELECT, INSERT, UPDATE, CREATE, DELETE ON wordpress.* TO 'wordpress' IDENTIFIED BY 'mypass';

This works fine so far and I don’t think my WordPress installation needs more privileges. Note that the ALTER and DROP statements are missing from my list, which could interfere with future updates. But we’ll see…