How I solved Fatal error: Allowed memory exhausted

Fatal error: Allowed memory size of xxxxxxxx bytes exhausted (tried to allocate 2348617 bytes) in /home4/xxx/public_html/wp-includes/plugin.php on line xxx

This is what I saw at some time while running Debug Bar plugin on my site and I decided to solve it. After some search I tried the solutions provided by most of hosts, like editing wp-config.php file to increase memory limit, editing .htaccess, with no results.

On some site I found a gold information: some times this error is generated because the database, due to some tables columns are created with “LONGTEXT” type.

There are four types of text columns in MySQL: TINYTEXT , TEXT , MEDIUMTEXT , and LONGTEXT . As the name suggests, each type has a cap for the amount of data it can hold. The TINYTEXT column can hold up to 255 characters, while the LONGTEXT column can hold up to 4 gigabytes of data. This was all the information I needed to solve the problem. Can you see it?

If not, this is what I did.

1. I backed up the database.

2. I exported the database to my computer (via phpmyadmin) as a sql file.

3. Using Notepad’s function Replace I edited the sql file – replaced all “LONGTEXT” with “MEDIUMTEXT”.

4. Using phpmyadmin I dropped all the tables in the database.

5. Using server’s function Restore function I imported the edited sql file as new tables. Done! The error is now gone.

I would suggest anyone facing the allowed memory exhausted error to try this solution first, before editing any file on server.

IMPORTANT: always start by backing-up the database or (even better) the whole website.