mysql

Everyday I use a database called MySQL and here is a list of stuff I've found useful about MySQL.

MySQL: Count occurrences of string

Feb
17
2010
Tagged in , , &
Drupal and MySQL

Today I needed to quickly find out a list of node's which did not contain a certain token (one we use on PPOnline to insert adverts into articles). There were meant to be 2 of these tokens per article but we had noticed some only had one. Some didn't have any at all!

Now, this might already exist as a neat function somewhere, but I couldn't find it. So I wrote this little query to find the number of occurrences of a substring in a larger block of text.

I did look into using the SUBSTRING() and SUBSTRING_INDEX() commands, however I couldn't see a way of efficiently using them to find any number of occurrences. So I settled on the following…

Generate random string in MySQL

Jul
10
2008

Have you ever wanted to generate a random string in MySQL, say for assigning a random password to a list of users? Well here is a useful tip!

How to weigh terms alphabetically

Aug
07
2007
MySQL and Drupal

Following on from my Numbering Rows in MySQL article, today I needed to populate the weight column of the term_data table for about a hundred terms so that they incremented in alphabetical order. This was, on the face of it, a very tedious task; click edit, select weight from drop-down, submit, 'goto 1'.

As I said in my Numbering Rows in MySQL article, I don't like tedious - but I do like over-complicated methods which actually make my life more interesting and less tedious... Enter a nifty MySQL script!

Ordering Menu Items Alphabetically

Jan
02
2007

Faced with a tedious task of ordering a set of rows using a weight column? Don't want to type the numbers out? Would rather find a difficult but more interesting method? I have the answer for you!

Drop all tables in a MySQL database

Oct
10
2006

This morning I am faced with a task that will involve repeatedly dropping and reimporting a lot of data. MySQL has DROP TABLE and DROP DATABASE but there is no command to drop all tables or truncate the database.

Follow Me

Recent comments

ed hardy 14 hours ago
Replies.... 4 days ago
Or in 4 days ago
A few tweaks 5 days ago
Nice 5 days ago
Thanks a million 1 week ago
Syndicate content