Error when importing to server - mysql

SQL query:
CREATE TABLE `wp_layerslider` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`author` int(10) NOT NULL DEFAULT '0',
`name` varchar(100) COLLATE utf8mb4_unicode_520_ci DEFAULT '',
`slug` varchar(100) COLLATE utf8mb4_unicode_520_ci DEFAULT '',
`data` mediumtext COLLATE utf8mb4_unicode_520_ci NOT NULL,
`date_c` int(10) NOT NULL,
`date_m` int(10) NOT NULL,
`schedule_start` int(10) NOT NULL DEFAULT '0',
`schedule_end` int(10) NOT NULL DEFAULT '0',
`flag_hidden` tinyint(1) NOT NULL DEFAULT '0',
`flag_deleted` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
MySQL said: Documentation
1273 - Unknown collation: 'utf8mb4_unicode_520_ci'
When attempting to import a database. I'm very new to all of this, hoping someone can assist in simple terms for me

could be you are using an oldeversion of mysql db .. and the collate you need is not avialable .. you could use try alter the table or change the collate
ALTER TABLE `wp_layerslider` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci

Related

#1005 - Can't create table TABLE NAME' (errno: 150) (Details…)

I have deleted the user table and now wanted to impotieren another user table of the same forensoftware.
But it does not work
I Add SQL Backup Table
https://pastebin.com/uZjbUFEk
This Error Comming on PHPmyAdmin
CREATE TABLE `wcf1_user` (
`userID` int(10) NOT NULL,
`username` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`email` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`password` varchar(100) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`accessToken` char(40) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`languageID` int(10) NOT NULL DEFAULT '0',
`registrationDate` int(10) NOT NULL DEFAULT '0',
`styleID` int(10) NOT NULL DEFAULT '0',
`banned` tinyint(1) NOT NULL DEFAULT '0',
`banReason` mediumtext COLLATE utf8_unicode_ci,
`banExpires` int(10) NOT NULL DEFAULT '0',
`activationCode` int(10) NOT NULL DEFAULT '0',
`lastLostPasswordRequestTime` int(10) NOT NULL DEFAULT '0',
`lostPasswordKey` varchar(40) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`lastUsernameChange`[...]
#1005 - Can't create table 'censored.wcf1_user' (errno: 150) (Details…)

Migrating an .sql database to WordPress

I have an SQL file for a database from an old custom blog CMS. I am trying to import the articles into WordPress but I am now stuck. So far, I have managed to isolate the table structures for the CMS (see below). I have also identified the columns that i need. These are (Post, Title, Date, Image, Category). Now I have to map these columns to some columns in the Wordpress schema somehow and that is where I am getting stuck.
Here is the SQL structure of the database:
CREATE TABLE `ads_ng_ads` (
`id` int(10) unsigned NOT NULL auto_increment,
`ad_type` enum('media','text','html') character set latin1 collate latin1_bin NOT NULL,
`media_type` enum('image','flash','other') character set latin1 collate latin1_bin default NULL,
`media_width` smallint(6) default NULL,
`media_height` smallint(6) default NULL,
`media_size` int(6) default NULL,
`media_path` varchar(128) character set latin1 collate latin1_bin default NULL,
`uri` varchar(128) character set utf8 collate utf8_bin NOT NULL,
`is_hidden` tinyint(1) NOT NULL,
`created_on` int(11) NOT NULL,
`active_from` int(11) NOT NULL,
`active_to` int(11) NOT NULL,
`room_id` int(11) default NULL,
`geo_target` int(11) default NULL,
`alternative` text character set utf8 NOT NULL,
`zone_target` text character set ascii collate ascii_bin NOT NULL,
`uri_target` text character set utf8 collate utf8_bin NOT NULL,
PRIMARY KEY (`id`),
KEY `zone_target` (`is_hidden`,`active_from`,`active_to`,`geo_target`)
) ENGINE=MyISAM AUTO_INCREMENT=757 DEFAULT CHARSET=latin1;
CREATE TABLE `ads_ng_statistics` (
`ad_id` int(10) unsigned NOT NULL,
`date` int(11) NOT NULL,
`views` mediumint(8) unsigned NOT NULL default '0',
`clicks` mediumint(8) unsigned NOT NULL default '0',
PRIMARY KEY (`ad_id`,`date`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE `countries` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(100) NOT NULL,
`alias` varchar(3) NOT NULL,
`restricted` tinyint(3) NOT NULL default '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=253 DEFAULT CHARSET=utf8;
CREATE TABLE `featured_column` (
`id` int(11) unsigned NOT NULL auto_increment,
`date_modified` timestamp NOT NULL default CURRENT_TIMESTAMP,
`date_created` timestamp NOT NULL default '1000-01-01 00:00:00',
`title` varchar(255) NOT NULL,
`alias` varchar(255) NOT NULL,
`body` text NOT NULL,
`body_html` text NOT NULL,
`user_id` int(11) NOT NULL,
`tags` varchar(255) NOT NULL,
`summary` varchar(255) NOT NULL,
`in_homepage` int(1) NOT NULL default '0',
`img_title` int(1) NOT NULL default '0',
`meta_t` varchar(255) NOT NULL,
`meta_k` varchar(255) NOT NULL,
`meta_d` varchar(255) NOT NULL,
`public` int(1) NOT NULL default '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=1381 DEFAULT CHARSET=utf8;
Assuming that you're using the latest WordPress version(4.9.1), you just need to create a script that will import all data to table wp_posts for example if you want to import as WordPress posts. Example: "Title" to "post_title", "post" to "post_content", etc.

mysql #1215 - Cannot add foreign key constraint - but why?

we have the following script:
CREATE TABLE `dataBodyChanges` (
`id` int( 10 ) unsigned NOT NULL AUTO_INCREMENT ,
`numberOfContainers` int( 11 ) NOT NULL ,
`quantityPerContainer` int( 11 ) NOT NULL ,
`grossWeight` double NOT NULL ,
`comment` varchar( 1000 ) NOT NULL ,
`file` int( 10 ) unsigned DEFAULT NULL ,
`user` int( 10 ) unsigned NOT NULL ,
`dataBodyId` int( 10 ) unsigned NOT NULL ,
`created_at` timestamp NULL DEFAULT NULL ,
`updated_at` timestamp NULL DEFAULT NULL ,
PRIMARY KEY ( `id` ) ,
KEY `databodychanges_databodyid_foreign` ( `dataBodyId` ) ,
CONSTRAINT `databodychanges_databodyid_foreign` FOREIGN KEY ( `dataBodyId` ) REFERENCES `dataBodies` ( `id` )
) ENGINE = InnoDB AUTO_INCREMENT =1113 DEFAULT CHARSET = utf8;
with mysql output:
1215 - Cannot add foreign key constraint
the other table is:
USE material;
CREATE TABLE `dataBodies` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`partNumber` varchar(8) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`totalOrderQuantity` varchar(9) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`containerPart` varchar(8) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`numberOfContainers` varchar(9) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`quantityPerContainer` varchar(9) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`kanbanNumber` varchar(4) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`matHandlingCode` varchar(12) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`grossWeight` varchar(9) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`partRemarks` varchar(18) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`AI11Z` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`AI12Z` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`AI13Z` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`AI14Z` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`AI15Z` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`AI16Z` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`AI17Z` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`filler` varchar(163) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`dataHeaderId` int(10) unsigned DEFAULT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `databodies_dataheaderid_foreign` (`dataHeaderId`),
CONSTRAINT `databodies_dataheaderid_foreign` FOREIGN KEY (`dataHeaderId`) REFERENCES `dataHeaders` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1113 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
We do not know why....
can anybody please help who is master in this?
Thank you in advance!
When you are creating tables, it will check if dependent table is already created, if not it will throw that error.
For which you first need to set,
set foreign_key_checks = false; // above all
Above line will temporarily disable foreign key checks if any.
Then run above query. It will work. then after executing your queries, enable it by,
set foreign_key_checks = true;

What could be wrong here

DROP TABLE IF EXISTS 'ci_sessions';
CREATE TABLE 'ci_sessions' (
'session_id' varchar(40) COLLATE utf8_bin NOT NULL DEFAULT '0',
'ip_address' varchar(16) COLLATE utf8_bin NOT NULL DEFAULT '0',
'user_agent' varchar(120) COLLATE utf8_bin DEFAULT NULL,
'last_activity' int(10) unsigned NOT NULL DEFAULT '0',
'user_data' text COLLATE utf8_bin NOT NULL, PRIMARY KEY ('session_id'),
KEY 'last_activity_idx' ('last_activity') )
ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
I've tried to run this code on phpMyAdmin and it says
#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 ''ci_sessions'' at line 1
It's the same error in all your table and column names. You use ' while you should use backticks:
`
So this should work:
DROP TABLE IF EXISTS `ci_sessions`;
CREATE TABLE `ci_sessions` (
`session_id` varchar(40) COLLATE utf8_bin NOT NULL DEFAULT '0',
`ip_address` varchar(16) COLLATE utf8_bin NOT NULL DEFAULT '0',
`user_agent` varchar(120) COLLATE utf8_bin DEFAULT NULL,
`last_activity` int(10) unsigned NOT NULL DEFAULT '0',
`user_data` text COLLATE utf8_bin NOT NULL, PRIMARY KEY (`session_id`),
KEY `last_activity_idx` (`last_activity`) )
ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
As a sidenote - you use NOT NULL and then set the default value to the string 0. quite often. That indicates bad practice, or at least more work for later queries. A column named last_activity for example indicates that null values should be allowed...
Second sidenote - last_activity would typically be a DATETIME column, not an int(10)

Whats wrong in my sql query?

Here I'm trying to create a new table, but I don't know what I did wrong when creating the table.
SQL query:
CREATE DATABASE IF NOT EXISTS wan_ecommerce;
USE wan_ecommerce
CREATE TABLE IF NOT EXISTS users (
user_id int(11) NOT NULL AUTO_INCREMENT COMMENT,
user_name varchar(64) COLLATE utf8_unicode_ci NOT NULL COMMENT,
user_password_hash varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT,
user_email varchar(64) COLLATE utf8_unicode_ci NOT NULL COMMENT,
user_active tinyint(1) NOT NULL DEFAULT '0' COMMENT,
user_activation_hash varchar(40) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT,
user_password_reset_hash char(40) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT,
user_password_reset_timestamp bigint(20) DEFAULT NULL COMMENT,
user_rememberme_token varchar(64) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT,
user_failed_logins tinyint(1) NOT NULL DEFAULT '0' COMMENT,
user_last_failed_login int(10) DEFAULT NULL COMMENT,
user_registration_datetime datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
user_registration_ip varchar(39) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0.0.0.0',
PRIMARY KEY (`user_id`),
UNIQUE KEY user_name (`user_name`),
UNIQUE KEY user_email (`user_email`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='user data';
When I run this I get an error. I've added ; after use wan_ecommerce;, but I'm still getting:
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 '
user_name varchar(64) COLLATE utf8_unicode_ci NOT NULL COMMENT,
user_passwo' at line 2
What am I doing wrong here?
How can I solve this?
Use semicolon to terminate each statement.
CREATE DATABASE IF NOT EXISTS wan_ecommerce;
USE wan_ecommerce; -- <----- semi colon was missing
CREATE TABLE IF NOT EXISTS users (
-- ....
The 'COMMENT' is a keyword. If you use it,you must to add a description to flowing 'COMMENT',like this code:
CREATE DATABASE IF NOT EXISTS wan_ecommerce;
USE wan_ecommerce
CREATE TABLE IF NOT EXISTS users (
user_id int(11) NOT NULL AUTO_INCREMENT COMMENT 'id',
user_name varchar(64) COLLATE utf8_unicode_ci NOT NULL COMMENT 'name',
user_password_hash varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT 'password_hash',
user_email varchar(64) COLLATE utf8_unicode_ci NOT NULL COMMENT 'email',
user_active tinyint(1) NOT NULL DEFAULT '0' COMMENT 'active',
user_activation_hash varchar(40) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'activation_hash',
user_password_reset_hash char(40) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'password_reset_hash',
user_password_reset_timestamp bigint(20) DEFAULT NULL COMMENT 'password_reset_timestamp',
user_rememberme_token varchar(64) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'rememberme_token',
user_failed_logins tinyint(1) NOT NULL DEFAULT '0' COMMENT 'failed_logins',
user_last_failed_login int(10) DEFAULT NULL COMMENT 'last_failed_login',
user_registration_datetime datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
user_registration_ip varchar(39) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0.0.0.0',
PRIMARY KEY (`user_id`),
UNIQUE KEY user_name (`user_name`),
UNIQUE KEY user_email (`user_email`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='user data';
If you don't need this 'COMMENT',you can remove it.The code like this:
CREATE DATABASE IF NOT EXISTS wan_ecommerce;
USE wan_ecommerce
CREATE TABLE IF NOT EXISTS users (
user_id int(11) NOT NULL AUTO_INCREMENT,
user_name varchar(64) COLLATE utf8_unicode_ci NOT NULL,
user_password_hash varchar(255) COLLATE utf8_unicode_ci NOT NULL,
user_email varchar(64) COLLATE utf8_unicode_ci NOT NULL,
user_active tinyint(1) NOT NULL DEFAULT '0',
user_activation_hash varchar(40) COLLATE utf8_unicode_ci DEFAULT NULL,
user_password_reset_hash char(40) COLLATE utf8_unicode_ci DEFAULT NULL,
user_password_reset_timestamp bigint(20) DEFAULT NULL,
user_rememberme_token varchar(64) COLLATE utf8_unicode_ci DEFAULT NULL,
user_failed_logins tinyint(1) NOT NULL DEFAULT '0',
user_last_failed_login int(10) DEFAULT NULL,
user_registration_datetime datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
user_registration_ip varchar(39) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0.0.0.0',
PRIMARY KEY (`user_id`),
UNIQUE KEY user_name (`user_name`),
UNIQUE KEY user_email (`user_email`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='user data';