SQL syntax errors when importing database into phpMyAdmin (MAMP) - mysql

In order to import a 120Mb database into phpMyAdmin with MAMP I split it up using the following:
split -l 100 /Applications/MAMP/htdocs/test/database_test_wordpress.sql /Applications/MAMP/htdocs/test/dbpart-
However when importing the second part I get the error:
Error
SQL query:
CREATE TABLE `wp_comments` (
`comment_ID` BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT ,
`comment_post_ID` BIGINT( 20 ) UNSIGNED NOT NULL DEFAULT '0',
`comment_author` TINYTEXT NOT NULL ,
`comment_author_email` VARCHAR( 100 ) NOT NULL DEFAULT '',
`comment_author_url` VARCHAR( 200 ) NOT NULL DEFAULT '',
`comment_author_IP` VARCHAR( 100 ) NOT NULL DEFAULT '',
`comment_date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
`comment_date_gmt` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
`comment_content` TEXT NOT NULL ,
`comment_karma` INT( 11 ) NOT NULL DEFAULT '0',
`comment_approved` VARCHAR( 20 ) NOT NULL DEFAULT '1',
`comment_agent` VARCHAR( 255 ) NOT NULL DEFAULT '',
`comment_type` VARCHAR( 20 ) NOT NULL DEFAULT '',
`comment_parent` BIGINT( 20 ) UNSIGNED NOT NULL DEFAULT '0',
`user_id` BIGINT( 20 ) UNSIGNED NOT NULL DEFAULT '0',
PRIMARY KEY ( `comment_ID` ) ,
KEY `comment_post_ID` ( `comment_post_ID` ) ,
MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 18
Do I need to upgrade the database somehow? Or am I way off?! Sorry, new to this :-)
Note: I first tried increasing upload_max_filesize, memory_limit and post_max_size in MAMP's php.ini but on import I got a MySQL server has gone away error.

split is a linux command that will just slice text. You can't just do that and expect an import to work. In your particular example, the creation of a table is not being properly finished by a ;, which means you are most likely missing the creation of indexes or constraints below the cut part of the text.
I wouldn't slice the file at all and import the whole SQL file from the console instead of using php for that. This should do the trick:
mysql -u username -p database_name < file.sql

Thanks guys for pointing out that split was not the way to go!
Instead I managed to upload the original 120Mb file by editing the following limits before restarting MAMP:
In MAMP/bin/php/php5.4.10/conf/php.ini I changed the memory_limit to 200M, the post_max_size to 200M and the upload_max_filesize to 120M.
I then copied MAMP/Library/support-files/my-large.cnf to MAMP/Library and renamed it to my.cnf before setting max_allowed_packet to 100M
Was pointed in this direction MAMP FAQs and https://stackoverflow.com/a/13613140/767761

Related

I have exported a Mysql Database, and am having syntax issues importing to a newer version

I am trying to import a Mysql DB into a new instance on an updated domain. I am getting the below syntax error, I cant work out what is wrong and everythig I try isnt working.
can you help?
SQL query:
--
-- Database: 'pringlerfe'
-- -- --------------------------------------------------------
--
-- Table structure for table `adverts`
--
CREATE TABLE `adverts` (
`advers_id` INT( 11 ) NOT NULL ,
`advers_name` VARCHAR( 50 ) DEFAULT NULL ,
`advers_sqimg` VARCHAR( 50 ) DEFAULT NULL ,
`advers_squrl` VARCHAR( 100 ) DEFAULT NULL ,
`advers_towerimg` VARCHAR( 50 ) DEFAULT NULL ,
`advers_url` VARCHAR( 100 ) DEFAULT NULL ,
`advers_des` VARCHAR( 100 ) DEFAULT NULL ,
`advers_display` VARCHAR( 50 ) DEFAULT NULL
) ENGINE = MYISAM DEFAULT CHARSET = latin1;
MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '
--
-- Table struc' at line 3 `
CREATE TABLE adverts (
advers_id int NOT NULL,
advers_name varchar( 50 ) DEFAULT NULL,
advers_sqimg VARCHAR( 50 ) DEFAULT NULL,
advers_squrl VARCHAR( 100 ) DEFAULT NULL,
advers_towerimg VARCHAR( 50 ) DEFAULT NULL,
advers_url VARCHAR( 100 ) DEFAULT NULL,
advers_des VARCHAR( 100 ) DEFAULT NULL,
advers_display VARCHAR( 50 ) DEFAULT NULL
);

#1064 MySQL error on webhost

I am getting the following error on MySQL:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(6) NOT NULL,
`Modified` datetime(6) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHA' at line 14
I have a SQL script that creates a database and some tables. It uploads perfectly on my localhost but when I import it on my web host using phpmyadmin it gives the above errror.
The code it highlights from the script is:
CREATE TABLE IF NOT EXISTS `dbo_countries` (
`CountryId` INT( 11 ) NOT NULL ,
`Code` VARCHAR( 50 ) DEFAULT NULL ,
`ISO2` VARCHAR( 10 ) DEFAULT NULL ,
`ISO3` VARCHAR( 10 ) DEFAULT NULL ,
`RegionId` INT( 11 ) DEFAULT NULL ,
`Name` VARCHAR( 255 ) DEFAULT NULL ,
`Created` DATETIME( 6 ) NOT NULL ,
`Modified` DATETIME( 6 ) DEFAULT NULL
) ENGINE = INNODB DEFAULT CHARSET = utf8 AUTO_INCREMENT =243;
The MySQL DATETIME datatype doesn't accept a length, size, digit specifier. The error is being thrown because it's a syntax violation.
To declare a DATETIME column, do it like this, without any following parens:
`Created` DATETIME NOT NULL

Wordpress PhpMyAdmin import db error

Im trying to move my wordpress site over to another hosting. I have exported the db and I am re-importing it onto the hosting. The database does have a different name but I have updated the file.
Here is the error I receive when trying to import it:
Error
SQL query:
CREATE TABLE IF NOT EXISTS `wp_commentmeta` (
`meta_id` bigint( 20 ) unsigned NOT NULL AUTO_INCREMENT ,
`comment_id` bigint( 20 ) unsigned NOT NULL DEFAULT '0',
`meta_key` varchar( 255 ) DEFAULT NULL ,
`meta_value` longtext,
PRIMARY KEY ( `meta_id` ) ,
KEY `comment_id` ( `comment_id` ) ,
KEY `meta_key` ( `meta_key` )
) TYPE = MYISAM AUTO_INCREMENT =17;
MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TYPE=MyISAM AUTO_INCREMENT=17' at line 9
I had a look on here and a lot of people said it was because Add CREATE PROCEDURE / FUNCTION / EVENT statement needed ticking, but I have done this.
As documented under CREATE TABLE Syntax:
Note
The older TYPE option was synonymous with ENGINE. TYPE was deprecated in MySQL 4.0 and removed in MySQL 5.5. When upgrading to MySQL 5.5 or later, you must convert existing applications that rely on TYPE to use ENGINE instead.
Therefore, you want:
CREATE TABLE IF NOT EXISTS `wp_commentmeta` (
`meta_id` bigint( 20 ) unsigned NOT NULL AUTO_INCREMENT ,
`comment_id` bigint( 20 ) unsigned NOT NULL DEFAULT '0',
`meta_key` varchar( 255 ) DEFAULT NULL ,
`meta_value` longtext,
PRIMARY KEY ( `meta_id` ) ,
KEY `comment_id` ( `comment_id` ) ,
KEY `meta_key` ( `meta_key` )
) ENGINE = MYISAM AUTO_INCREMENT =17;

How do I eliminate error message 1064 when trying to create table with BLOB type columns?

I keep getting an error for this table. I've never created a table using blob's before so I do not understand the error message. Can someone explain the error?
CREATE TABLE `teamc`.`newsletter` (
`title` VARCHAR( 100 ) NOT NULL ,
`subtitle` VARCHAR( 100 ) NOT NULL ,
`date` DATE NOT NULL ,
`jpg` BLOB BINARY NULL DEFAULT NULL ,
`pdf` BLOB BINARY NULL DEFAULT NULL ,
PRIMARY KEY ( `title` , `date` )
) ENGINE = InnoDB;
MySQL gives me the following error:
Documentation 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'BINARY NULL DEFAULT NULL, pdf BLOB BINARY NULL DEFAULT NULL, PRIMARY KEY (`tit' at line 1
BINARY is a type, BLOB is a type - and you cannot specify multiple types for the same column. You pick one:
CREATE TABLE `newsletter` (
`title` VARCHAR( 100 ) NOT NULL ,
`subtitle` VARCHAR( 100 ) NOT NULL ,
`date` DATE NOT NULL ,
`jpg` BLOB NULL DEFAULT NULL ,
`pdf` BLOB NULL DEFAULT NULL ,
PRIMARY KEY ( `title` , `date` )
) ENGINE = InnoDB;

#1067 - Invalid default value for 'membership'

I am using a SQL file included in my program and once I fixed an issue that I was able to find the answer to in here (THANK YOU).. I ran it again and got the following error:
SQL query:
# Create table structure for 'member' table
CREATE TABLE member(
memberID INT( 11 ) NOT NULL AUTO_INCREMENT ,
title VARCHAR( 80 ) NOT NULL DEFAULT '',
firstname VARCHAR( 80 ) NOT NULL DEFAULT '',
lastname VARCHAR( 80 ) NOT NULL DEFAULT '',
email VARCHAR( 80 ) NOT NULL DEFAULT '',
address VARCHAR( 80 ) NOT NULL DEFAULT '',
suburb VARCHAR( 80 ) NOT NULL DEFAULT '',
state VARCHAR( 80 ) NOT NULL DEFAULT '',
country VARCHAR( 80 ) NOT NULL DEFAULT '',
postcode VARCHAR( 11 ) NOT NULL DEFAULT '',
mobile VARCHAR( 80 ) NOT NULL DEFAULT '',
phone VARCHAR( 80 ) NOT NULL DEFAULT '',
fax VARCHAR( 80 ) NOT NULL DEFAULT '',
membership INT( 2 ) NOT NULL DEFAULT '',
payment INT( 2 ) NOT NULL DEFAULT '',
startdate BIGINT( 14 ) NOT NULL DEFAULT 0,
enddate BIGINT( 14 ) NOT NULL DEFAULT 0,
userID INT( 11 ) NOT NULL ,
PRIMARY KEY ( memberID ) ,
UNIQUE (
memberID
)
) ENGINE = MYISAM ;
MySQL said:
#1067 - Invalid default value for 'membership'
What do I need to change to make this work ? this is an older script, but I am not knowledgeable enough to know what needs to be changed for MySQL 5.5 version.
Thank you so much for your help!
And I'm sure there will be other errors popping up after I fix this one..
The membership column is an int, but you're giving it a default string value of ''. So change
membership INT( 2 ) NOT NULL DEFAULT '',
to
membership INT( 2 ) NOT NULL DEFAULT 0,
(0 or whatever default value you want for that field.)
I was getting:
Incorrect integer value: '' for column 'column_name' at row 1
I've fixed it editing /etc/mysql/my.cnf or /etc/mysql/mysql.conf.d/mysqld.cnf files. Then find the following line:
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
and replace it for
sql-mode=""
and restart MySQL: service mysql restart