MySQL string replace

khaled —  March 9, 2012 — 1 Comment

One of the MySQL functions that is extremely useful is the MySQL REPLACE() function. The REPLACE syntax looks as follows:


For example, if for some reason you need to update the links in your body fields and replace all your current links URL with new links URL you can use the following query:
update my_table set body=replace(body,’’,'’);


Sometimes, while trying to run a query that contains large data size in MySQL, you will receive the following error: “Got packet bigger than ‘max_allowed_packet’ bytes”. This error is very common when dumping, restoring or inserting content that contains blob or large strings of data.

In order to resolve this error, all you need to do is to locate the used my.cnf and increase the max_allowed_packet variable. It is generally recommended to set it to 32M.

On Debian distributions, the cnf file is generally located at /etc/mysql/my.cnf.

Page 1 of 11