Web

mysql alternative to PHP substr_count function

The substr_count function in PHP counts the number of substring occurrences. This post describes how to create a mysql stored function to behave just like PHP’s substr_count function. This function can be created from your mysql console delimiter || DROP FUNCTION IF EXISTS substrCount|| CREATE FUNCTION substrCount(s VARCHAR(255), ss VARCHAR(255)) RETURNS TINYINT(3) UNSIGNED LANGUAGE SQL […]

Read More
Misc

Howto combine two columns into one in mysql

This is how you can combine (or concatenate or merge) data from two table columns into one column using a mysql SQL query. SELECT CONCAT(firstname,lastname) AS ‘name’ FROM tablename The result would be “firstname lastname” If you would like to insert this data into a new column INSERT INTO tablename (full_name) SELECT CONCAT(firstname,lastname) AS ‘name’ […]

Read More
Misc

MySQL search and replace

This is a simple SQL query to perform search and replace in a MySQL table update tablename set fieldname = replace(fieldname,’search_for_this’,’replace_with_this’);

Read More
Linux

mysql on a nondefault socket

It is sometimes necessary to run two instances of mysql, like in my case. I need a mysql database in addition to the one Zimbra uses. One solution to this problem is to run the mysql database on a non default socket. This can be done by changing the following line in my.cnf my.cnf [client] […]

Read More