Error (near "ON" at position 25) while importing Table for WORDPRESS ( A foreign key Error)
PhpMysqlWordpressPhp Problem Overview
I try to import a large file to my Database (WordPress), it shows some error like this:
Error
Static analysis:
1 errors were found during analysis.
Unrecognized keyword. (near "ON" at position 25)
SQL query: Edit Edit
SET FOREIGN_KEY_CHECKS = ON;
MySQL said: Documentation
#2006 - MySQL server has gone away
Php Solutions
Solution 1 - Php
I had the same error when I tried to migrate Drupal database to a new local apache server(I am using XAMPP on Windows machine). Actually I don't know the meaning of this error, but after trying steps below, I imported the database without errors. Hope this could help:
Changing php.ini at C:\xampp\php\php.ini
max_execution_time = 600
max_input_time = 600
memory_limit = 1024M
post_max_size = 1024M
Changing my.ini at C:\xampp\mysql\bin\my.ini
max_allowed_packet = 1024M
Solution 2 - Php
-
Goto XAMPP control panel>
-
Stop Apache and MySql services>
-
Click on Config of Apache>select php.ini and change the followings:
max_execution_time = 600
max_input_time = 600
memory_limit = 1024M
post_max_size = 1024M
-
Click on Config button of MySql and select my.ini and change:
max_allowed_packet = 1024M
-
Again Start the services and try.. i hope it will work.
Solution 3 - Php
Just specifying the above answer from Candle.
You will need to adjust only one line in my.ini:
-
Changing my.ini at C:\xampp\mysql\bin\my.ini OR click on config of XAMP>select php.ini and change the following:
max_allowed_packet = 50M // the value depends on the size of the .sql files you are trying upload.
Solution 4 - Php
This happens because of the importing connectivity issue with phpmyadmin when you import large DB, here is how you can import large data base to the phpmyadmin. First change the following files according to your DB size.
Changing php.ini at C:\xampp\php\php.ini
max_execution_time = 600
max_input_time = 600
memory_limit = 1024M
post_max_size = 1024M
Changing my.ini at C:\xampp\mysql\bin\my.ini
max_allowed_packet = 1024M
then run the shell from xampp control panel and enter the following command.
#mysql -p -u root DBname < c:\xampp\DBfolder\db.sql
EnterPassword: (usually it is blank).
then the process will start. :):):)
Solution 5 - Php
I had the same error when I tried to migrate Drupal database to a new local apache server(I am using XAMPP on Windows machine). Actually I don't know the meaning of this error, but after trying steps below, I imported the database without errors. Hope this could help:
Changing php.ini at C:\xampp\php\php.ini
max_execution_time = 600
max_input_time = 600
memory_limit = 1024M
post_max_size = 1024M
Changing my.ini at C:\xampp\mysql\bin\my.ini
max_allowed_packet = 1024M
Solution 6 - Php
I had the same problem when trying to import a Wordpess MySQL dump to a new server. In the end after an hour debugging I had to manually remove the following tables from the .sql file:
wp_cf7dbplugin_st wp_cf7dbplugin_submits
There were some really large values (possibly PDF files) stored in some of the fields which were causing a problem.
Imported fine after I removed the tables from the script.
Solution 7 - Php
If you are running Wamp, just do the following:
- Edit C:\wamp64\bin\mysql\mysql5.7.26\my.ini
- Increase the max packet size to 1024:
max_allowed_packet = 1024M
If after this you run into the error
> Script timeout passed, if you want to finish import, please resubmit > the same file and import will resume
Then do the following:
-
Go to C:\wamp64\alias\phpmyadmin.conf and increase the following values:
php_admin_value max_execution_time 360
php_admin_value max_input_time 360
Credits to RiggsFolly (https://stackoverflow.com/a/20364163/3231884) on the 3rd (optional) step
Solution 8 - Php
for me this issue resolved with
SQL compatibility mode: ANSI
I changed above to ANSI and this worked smoothly.
I've already set these..
max_execution_time = 120
max_input_time = 120
memory_limit = 512M
post_max_size = 64M
File was huge... so reimporting same file a few times imported everything smoothly.
Solution 9 - Php
For me my main goal was to make a stage site for my wordpress site, which had wordfence on it.
I was using plesk obsidian and had to update mariadb to get past the error in the main question here Error (near “ON” at position 25) while importing Table for WORDPRESS ( A foreign key Error)
which I was able to do by reading this blog article - https://support.plesk.com/hc/en-us/articles/213403429-How-to-upgrade-MySQL-5-5-to-5-6-5-7-or-MariaDB-5-5-to-10-0-10-1-10-2-on-Linux-
That took forever but got me passed the above error, but then I was getting this error on db import:
#1062 - Duplicate entry '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xEF\xBF\xBD\xEF\xBF\xBD' for key 'PRIMARY' when find and replace domain on wordfence
I was doing the domain find and replace in vscode "mydomain.com" with "stage.mydomain.com". The problem turned out to be that wordfence saves binary data or something to the database, and just opening it in vscode and saving it was altering that somehow, and thus throwing obscure duplicate entry error for primary key
The fix for the above was to not open, or alter, the .sql file in vscode but to do the find in replace with linux. This was the commands I ran to do this on Mac -
find and replace http: with https: -
perl -pi -w -e 's/http:\/\/mydomain.com/https:\/\/mydomain.com/g;' my_db_file.sql
find and replace mydomain.com with stage.mydomain.com -
perl -pi -w -e 's/mydomain.com/stage.mydomain.com/g;' my_db_file.sql
Solution 10 - Php
I would double check and make sure that you are import a compressed file and not the plain .sql file. use (gzip, bzip2, zip) and in your ini file adjust your max_allowed_packet from 1M to 5M or 10M.
Hopefully this helps someone.
Solution 11 - Php
After long time, i finally uninstall MAMP and try XAMPP. It worked. I don't know where was the problem i edit all the limits (created my.cnf with another values) but no success. With XAMPP those answers works...
Solution 12 - Php
I had the same problem and the solution was to increase the ram memory of the database. I was using a docker container.
Solution 13 - Php
Disable the foreign key checks on import page of phpmyadmin and then, try to import again
Solution 14 - Php
I have the same issue and none of the above answers helped me out sadly.
I post this because it may help someone one day.
The database dump i deal with is made via phpmyadmin, and it does not work maybe for some corrupted data in large database files.
The the solution for me is to dump the database via mysqldump
and import it via source
cmd under mysql.
it worked without any warnings or errors.
(i have not the time to dig why the phpmyadmin solution does not work as expected).
Hopfully this may help anybody out there.
cmd examples :
EXPORT : mysqldump -u db_user -p db_name > dump_file.sql
IMPORT : mysql> source dump_file.sql
Solution 15 - Php
The solutions provided here (those referring to the my.conf settings) did not resolve the problem in my case (at least not alone). It seems that there are multiple causes for the error. One is due to wrong phpMyAdmin export settings. What helped me was to check the option "IF NOT EXITS" during the export in phpMyAdmin (use "custom" settings).
Found the solution here: https://stackoverflow.com/a/70562262/7647311
Solution 16 - Php
I'm using Xampp. I tried all the solutions given here without success. In the end I rebooted my Mac and the import worked straight away.