#1064 SQL Syntax error - mysql

I understand this is a common and annoying problem so before I ask for an explanation I just want to say sorry.
As the title says I've been getting a 1064 syntax error from my MySQL db I imported in to php myadmin running wamp and building through netbeans.
I've checked out how other posts on the matter and have done reading about proper syntax but cannot see what my problem is.
An explanation would be greatly appreciated as I really want to learn this and improve my skills.
(if you have any questions about my code please ask)
Here's my full code:
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET #OLD_CHARACTER_SET_CLIENT=##CHARACTER_SET_CLIENT */;
/*!40101 SET #OLD_CHARACTER_SET_RESULTS=##CHARACTER_SET_RESULTS */;
/*!40101 SET #OLD_COLLATION_CONNECTION=##COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Database: `mydb`
--
CREATE DATABASE IF NOT EXISTS `mydb` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
USE `mydb`;
-- --------------------------------------------------------
--
-- Table structure for table `follow`
--
DROP TABLE IF EXISTS `follow`;
CREATE TABLE IF NOT EXISTS `follow` (
`follow_id` int(11) NOT NULL,
`follow_current_user` varchar(255) NOT NULL,
`follow_profile_user` varchar(255) NOT NULL,
`follow_timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=17 ;
--
-- Dumping data for table `follow`
--
INSERT INTO `follow` (`follow_id`, `follow_current_user`, `follow_profile_user`, `follow_timestamp`) VALUES
(13, 'dude', 'the', '2015-10-10 03:09:58'),
-- --------------------------------------------------------
--
-- Table structure for table `user`
--
DROP TABLE IF EXISTS `user`;
CREATE TABLE IF NOT EXISTS `user` (
`user_id` int(11) NOT NULL,
`user_email` varchar(255) NOT NULL,
`user_password` varchar(255) NOT NULL,
`user_firstname` text NOT NULL,
`user_lastname` text NOT NULL,
`user_avatar` varchar(255) NOT NULL,
`user_shortbio` text,
`user_username` varchar(255) NOT NULL,
`user_longbio` text,
`user_facebook` varchar(255) DEFAULT NULL,
`user_twitter` varchar(255) DEFAULT NULL,
`user_linkedin` varchar(255) DEFAULT NULL,
`user_stumbleupon` varchar(255) DEFAULT NULL,
`user_pinterest` varchar(255) DEFAULT NULL,
`user_googleplus` varchar(255) DEFAULT NULL,
`user_website` varchar(255) DEFAULT NULL,
`user_dob` date DEFAULT NULL,
`user_profession` text,
`user_gender` varchar(255) DEFAULT NULL,
`user_maritialstatus` varchar(255) DEFAULT NULL,
`user_address` text,
`user_backgroundpicture` varchar(255) NOT NULL,
`user_joindate` date NOT NULL,
`user_country` varchar(255) DEFAULT NULL,
`user_skype` varchar(255) DEFAULT NULL,
`user_github` varchar(255) DEFAULT NULL,
`user_youtube` varchar(255) DEFAULT NULL,
`user_vimeo` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=18 ;
--
-- Dumping data for table `user`
--
INSERT INTO `user` (`user_id`, `user_email`, `user_password`, `user_firstname`, `user_lastname`, `user_avatar`, `user_shortbio`, `user_username`, `user_longbio`, `user_facebook`, `user_twitter`, `user_linkedin`, `user_stumbleupon`, `user_pinterest`, `user_googleplus`, `user_website`, `user_dob`, `user_profession`, `user_gender`, `user_maritialstatus`, `user_address`, `user_backgroundpicture`, `user_joindate`, `user_country`, `user_skype`, `user_github`, `user_youtube`, `user_vimeo`) VALUES
(1, 'me#gmail.com', '123password123', 'Forname', 'Surname', '1470024_601216136604826_1065650331_n-884862517.jpg', 'Lorem ipsum.', 'username', 'Lorem ipsum', NULL, NULL, NULL, NULL, NULL, NULL, 'mysite.com', '1987-11-11', 'Student', 'Male', NULL, 'kablah', 'untitled-90969185.jpg', '2015- 11-11', 'Country', NULL, NULL, NULL, NULL),
--
-- --------------------------------------------------------
--
-- Table structure for table `view`
--
DROP TABLE IF EXISTS `view`;
CREATE TABLE IF NOT EXISTS `view` (
`view_id` int(11) NOT NULL,
`view_profile_user` varchar(255) NOT NULL,
`view_current_user` varchar(255) NOT NULL,
`view_timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=123 ;
--
-- Dumping data for table `view`
--
INSERT INTO `view` (`view_id`, `view_profile_user`, `view_current_user`, `view_timestamp`) VALUES
(65, 'blub', 'rugsworth', '2015-10-18 19:30:56'),
--
-- Indexes for dumped tables
--
--
-- Indexes for table `follow`
--
ALTER TABLE `follow`
ADD PRIMARY KEY (`follow_id`);
--
-- Indexes for table `user`
--
ALTER TABLE `user`
ADD PRIMARY KEY (`user_id`), ADD UNIQUE KEY `user_email` (`user_email`), ADD UNIQUE KEY `user_username` (`user_username`);
--
-- Indexes for table `view`
--
ALTER TABLE `view`
ADD PRIMARY KEY (`view_id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `follow`
--
ALTER TABLE `follow`
MODIFY `follow_id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=17;
--
-- AUTO_INCREMENT for table `user`
--
ALTER TABLE `user`
MODIFY `user_id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=18;
--
-- AUTO_INCREMENT for table `view`
--
ALTER TABLE `view`
MODIFY `view_id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=123;
/*!40101 SET CHARACTER_SET_CLIENT=#OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=#OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=#OLD_COLLATION_CONNECTION */;
And just the part of my code I think is causing the problem:
-- Dumping data for table `user`
--
INSERT INTO `user` (`user_id`, `user_email`, `user_password`, `user_firstname`, `user_lastname`, `user_avatar`, `user_shortbio`, `user_username`, `user_longbio`, `user_facebook`, `user_twitter`, `user_linkedin`, `user_stumbleupon`, `user_pinterest`, `user_googleplus`, `user_website`, `user_dob`, `user_profession`, `user_gender`, `user_maritialstatus`, `user_address`, `user_backgroundpicture`, `user_joindate`, `user_country`, `user_skype`, `user_github`, `user_youtube`, `user_vimeo`) VALUES
(1, 'me#gmail.com', '123password123', 'Forname', 'Surname', '1470024_601216136604826_1065650331_n-884862517.jpg', 'Lorem ipsum.', 'username', 'Lorem ipsum', NULL, NULL, NULL, NULL, NULL, NULL, 'mysite.com', '1987-11-11', 'Student', 'Male', NULL, 'kablah', 'untitled-90969185.jpg', '2015- 11-11', 'Country', NULL, NULL, NULL, NULL),
--
-- --------------------------------------------------------
--
-- Table structure for table `view`
--
DROP TABLE IF EXISTS `view`;
CREATE TABLE IF NOT EXISTS `view` (
`view_id` int(11) NOT NULL,
`view_profile_user` varchar(255) NOT NULL,
`view_current_user` varchar(255) NOT NULL,
`view_timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=123 ;
--
-- Dumping data for table `view`
--
INSERT INTO `view` (`view_id`, `view_profile_user`, `view_current_user`, `view_timestamp`) VALUES
(65, 'blub', 'rugsworth', '2015-10-18 19:30:56'),

You have a comma at the end of your INSERT INTO 'view' statement instead of a semicolon.
Should be:
INSERT INTO `view` (`view_id`, `view_profile_user`, `view_current_user`, `view_timestamp`)
VALUES (65, 'blub', 'rugsworth', '2015-10-18 19:30:56');
Does that fix it up?

Related

How to migrate MYSQL database with having different column name?

I have two database old.sql & new.sql.
I have user table named user in new.sql. and users in old.sql.
table structure for user from new.sql
--
-- Table structure for table `user`
--
DROP TABLE IF EXISTS `user`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `user` (
`id` int NOT NULL AUTO_INCREMENT,
`email` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`password` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`firstName` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`lastName` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`phoneNumber` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`role` enum('USER','ADMIN') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'USER',
`createdOn` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
PRIMARY KEY (`id`),
UNIQUE KEY `User_email_key` (`email`),
UNIQUE KEY `User_phoneNumber_key` (`phoneNumber`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = #saved_cs_client */;
and users from old.sql
DROP TABLE IF EXISTS `users`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `users` (
`id` int NOT NULL AUTO_INCREMENT,
`roleId` int NOT NULL,
`firstName` varchar(255) DEFAULT NULL,
`lastName` varchar(255) DEFAULT NULL,
`email` varchar(255) NOT NULL,
`password` varchar(255) DEFAULT NULL,
`status` tinyint(1) DEFAULT '1',
`resetPasswordExpires` datetime DEFAULT NULL,
`resetPasswordToken` varchar(255) DEFAULT NULL,
`createdAt` datetime NOT NULL,
`updatedAt` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`),
KEY `roleId` (`roleId`),
CONSTRAINT `Users_ibfk_1` FOREIGN KEY (`roleId`) REFERENCES `roles` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=884 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = #saved_cs_client */;
now I want to migrate user from old database to new database.
this is only one table, we have many tables to migrate data.
how can I achieve that ?
also we have done normalization in new database like
old.sql one table separated in 2 or 3 new tables in new database.
These DBs are on the same MySQL instance.
You can use a simple script like:
INSERT INTO
user (id, email, password, firstName, lastName, phoneNumber, role, createdOn)
SELECT
id, email, password, firstName, lastName, null, IF(roleId = 1, 'ADMIN', 'USER'), created
FROM users;
Just set correct roleId for condition and remove id if you need a new one.
Tiny example of the data transferring realization with some remarks: DEMO fiddle

Create Mysql tables

I downloaded the script that I want to install on my VPS, and as the creator who created this script said in the instructions, I import only the file that is called sql.sgl into the root folder where the database is created, but after that I can not run the script, and as I see in MySql no tables was created, so I wonder if there is a possibility to create everything from sql.sql file via commands in mysql, If someone can tell me just what commands in Linux I use to manually create all the tables and the rest from the file bellow:
anyway i just checked the error.log file and the error is on this script line 9 , please help , is this code ok ?
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_saha = "111.111.111.135";
$database_saha = "search";
$username_saha = "root";
$password_saha = "me111";
$saha = mysqli_connect($hostname_saha, $username_saha, $password_saha, $database_saha) or trigger_error(mysqli_error($saha),E_USER_ERROR);
mysqli_set_charset( $saha, 'utf8');
?>
-- version 4.6.0
-- http://www.phpmyadmin.net
--
-- Host: localhost:3306
-- Generation Time: Dec 04, 2016 at 12:02 PM
-- Server version: 5.5.52-cll-lve
-- PHP Version: 5.6.14
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET #OLD_CHARACTER_SET_CLIENT=##CHARACTER_SET_CLIENT */;
/*!40101 SET #OLD_CHARACTER_SET_RESULTS=##CHARACTER_SET_RESULTS */;
/*!40101 SET #OLD_COLLATION_CONNECTION=##COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `hello`
--
-- --------------------------------------------------------
--
-- Table structure for table `admin`
--
CREATE TABLE `admin` (
`id` int(11) NOT NULL,
`un` varchar(30) NOT NULL,
`pw` varchar(30) NOT NULL,
`demo` enum('Y','N') NOT NULL DEFAULT 'Y',
`max_pages` int(11) DEFAULT '20',
`max_content` int(11) DEFAULT '500'
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
--
-- Dumping data for table `admin`
--
INSERT INTO `admin` (`id`, `un`, `pw`, `demo`, `max_pages`, `max_content`) VALUES
(1, 'administrator', 'admin', 'N', 20, 500);
-- --------------------------------------------------------
--
-- Table structure for table `crawl`
--
CREATE TABLE `crawl` (
`id` int(11) NOT NULL,
`base_url` varchar(1000) NOT NULL,
`actual_url` varchar(2000) NOT NULL,
`title` varchar(2500) NOT NULL,
`description` varbinary(200) DEFAULT NULL,
`keywords` varbinary(200) DEFAULT NULL,
`content` varchar(500) DEFAULT NULL,
`current_url` varchar(2000) NOT NULL,
`last_update` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`deleted` enum('Y','N') DEFAULT 'N',
`block_update` enum('Y','N') DEFAULT 'N',
`visits` int(11) DEFAULT '0',
`manual` enum('Y','N') DEFAULT 'N'
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Table structure for table `settings`
--
CREATE TABLE `settings` (
`id` int(11) NOT NULL,
`base_url` varchar(1000) NOT NULL,
`actual_url` varchar(2000) NOT NULL,
`demo` enum('Y','N') DEFAULT 'N',
`date` timestamp NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
--
-- Indexes for dumped tables
--
--
-- Indexes for table `admin`
--
ALTER TABLE `admin`
ADD PRIMARY KEY (`id`),
ADD UNIQUE KEY `un` (`un`),
ADD UNIQUE KEY `un_2` (`un`);
--
-- Indexes for table `crawl`
--
ALTER TABLE `crawl`
ADD PRIMARY KEY (`id`);
--
-- Indexes for table `settings`
--
ALTER TABLE `settings`
ADD PRIMARY KEY (`id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `admin`
--
ALTER TABLE `admin`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=18;
--
-- AUTO_INCREMENT for table `crawl`
--
ALTER TABLE `crawl`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=747;
--
-- AUTO_INCREMENT for table `settings`
--
ALTER TABLE `settings`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=26;
/*!40101 SET CHARACTER_SET_CLIENT=#OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=#OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=#OLD_COLLATION_CONNECTION */;```

mysql update parent updates all column values in child

I have the following tables:
-users(not important here)
-students
-courses
-enrollments
the students and courses table have a "active column"
the enrollments table have a "course_active" and "student_active" column.
I am trying to set my DB in such a way that when I change active for student or course this will cascade to enrollments.
Unfortunately I am seeing that when I update an active value on "students/courses"
the whole column of "student active" or "course active" changes.
I would truly appreciate your input and assistance on this matter.
link to a fiddle for convenience:
http://sqlfiddle.com/#!9/8e2ce
here is my SQL:
-- phpMyAdmin SQL Dump
-- version 4.8.0.1
-- https://www.phpmyadmin.net/
--
-- Host: localhost
-- Generation Time: Apr 20, 2018 at 08:32 AM
-- Server version: 10.1.28-MariaDB
-- PHP Version: 7.1.10
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET #OLD_CHARACTER_SET_CLIENT=##CHARACTER_SET_CLIENT */;
/*!40101 SET #OLD_CHARACTER_SET_RESULTS=##CHARACTER_SET_RESULTS */;
/*!40101 SET #OLD_COLLATION_CONNECTION=##COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `schoolcrm2`
--
-- --------------------------------------------------------
--
-- Table structure for table `courses`
--
CREATE TABLE `courses` (
`id` int(5) NOT NULL,
`name` varchar(50) NOT NULL,
`description` text NOT NULL,
`start_date` date NOT NULL,
`end_date` date NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`active` tinyint(1) NOT NULL DEFAULT '1',
`added_by` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `enrollments`
--
CREATE TABLE `enrollments` (
`id` int(5) NOT NULL,
`student_id` int(11) NOT NULL,
`course_id` int(11) NOT NULL,
`user_id` int(11) DEFAULT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`student_active` int(1) NOT NULL DEFAULT '1',
`course_active` int(1) NOT NULL DEFAULT '1',
`added_by` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `students`
--
CREATE TABLE `students` (
`id` int(5) NOT NULL,
`email` varchar(40) NOT NULL,
`name` varchar(30) NOT NULL,
`phone` varchar(30) NOT NULL,
`password` varchar(255) NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`active` tinyint(1) NOT NULL DEFAULT '1',
`added_by` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `users`
--
CREATE TABLE `users` (
`id` int(5) NOT NULL,
`email` varchar(50) NOT NULL,
`name` varchar(50) NOT NULL,
`phone` varchar(30) NOT NULL,
`password` varchar(255) NOT NULL,
`role` enum('1','2','3') DEFAULT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`active` tinyint(1) NOT NULL DEFAULT '1',
`added_by` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Indexes for dumped tables
--
--
-- Indexes for table `courses`
--
ALTER TABLE `courses`
ADD PRIMARY KEY (`id`);
--
-- Indexes for table `enrollments`
--
ALTER TABLE `enrollments`
ADD PRIMARY KEY (`id`);
--
-- Indexes for table `students`
--
ALTER TABLE `students`
ADD PRIMARY KEY (`id`),
ADD UNIQUE KEY `email` (`email`);
--
-- Indexes for table `users`
--
ALTER TABLE `users`
ADD PRIMARY KEY (`id`),
ADD UNIQUE KEY `email` (`email`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `courses`
--
ALTER TABLE `courses`
MODIFY `id` int(5) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `enrollments`
--
ALTER TABLE `enrollments`
MODIFY `id` int(5) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `students`
--
ALTER TABLE `students`
MODIFY `id` int(5) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `users`
--
ALTER TABLE `users`
MODIFY `id` int(5) NOT NULL AUTO_INCREMENT;
ALTER TABLE `enrollments`
ADD CONSTRAINT `enrollments_to_courses` FOREIGN KEY (`course_active`) REFERENCES `courses` (`is_active`) ON UPDATE CASCADE,
ADD CONSTRAINT `enrollments_to_students` FOREIGN KEY (`student_active`) REFERENCES `students` (`is_active`) ON UPDATE CASCADE;
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=#OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=#OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=#OLD_COLLATION_CONNECTION */;

Wordpress thousand of categories crashing site

I have a big website, at the moment i have about 10k unique visitors daily, I have 2000 categories, 12k Tags, 36k custom taxonomies.
It's not a design flaw, as its a website to watch online movies, I used, categories for Seasons and stuff like that, the custom taxonomies are Actors, regizors etc.
The problem is that my hosting keeps crashing with 100% processor, the resources cannot be an issue, as i have my own server with 4xXeon, 64 GB ram.
I have isolated the problem, and it's due to very slow queries for example, what are my options? :
# Time: 160830 17:01:20
# User#Host: razvypp[razvypp] # localhost []
# Query_time: 9.159090 Lock_time: 0.001680 Rows_sent: 30 Rows_examined: 420117
SET timestamp=1472565680;
SELECT wphn_posts.ID
FROM wphn_posts
INNER JOIN wphn_term_relationships
ON (wphn_posts.ID = wphn_term_relationships.object_id)
WHERE 1=1
AND ( wphn_term_relationships.term_taxonomy_id IN (3630,
4955,4956,4957,4958,4959,4960,4961,4962,4963,4964,4965,
4966,4967,4968,4969,4970,4971,4972,4973,4974,4975,4976,
4977,4978,4979,4980,4981,4982,4983,4984,4985,4986,4987,
4988,4989,4990,4991,4992,4993,4994,4995,4996,4997,4998,
4999,5000,5001,5002,5003,5004,5005,5006,5007,5008,5009,
5010,5011,5012, ... (hundreds of numbers) ...,49740,49779)
Here is a dump of the tables
-- phpMyAdmin SQL Dump
-- version 4.4.15
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: 30 Aug 2016 la 15:17
-- Versiune server: 5.5.51-log
-- PHP Version: 5.5.37
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET #OLD_CHARACTER_SET_CLIENT=##CHARACTER_SET_CLIENT */;
/*!40101 SET #OLD_CHARACTER_SET_RESULTS=##CHARACTER_SET_RESULTS */;
/*!40101 SET #OLD_COLLATION_CONNECTION=##COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `trolio`
--
-- --------------------------------------------------------
--
-- Structura de tabel pentru tabelul `wphn_posts`
--
CREATE TABLE IF NOT EXISTS `wphn_posts` (
`ID` bigint(20) unsigned NOT NULL,
`movie_type` int(2) NOT NULL,
`post_author` bigint(20) unsigned NOT NULL DEFAULT '0',
`post_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`post_date_gmt` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`post_content` longtext NOT NULL,
`post_title` text NOT NULL,
`post_excerpt` text NOT NULL,
`post_status` varchar(20) NOT NULL DEFAULT 'publish',
`comment_status` varchar(20) NOT NULL DEFAULT 'open',
`ping_status` varchar(20) NOT NULL DEFAULT 'open',
`post_password` varchar(20) NOT NULL DEFAULT '',
`post_name` varchar(200) NOT NULL DEFAULT '',
`to_ping` text NOT NULL,
`pinged` text NOT NULL,
`post_modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`post_modified_gmt` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`post_content_filtered` longtext NOT NULL,
`post_parent` int(20) unsigned NOT NULL DEFAULT '0',
`guid` varchar(255) NOT NULL DEFAULT '',
`menu_order` int(11) NOT NULL DEFAULT '0',
`post_type` varchar(20) NOT NULL DEFAULT 'post',
`post_mime_type` varchar(100) NOT NULL DEFAULT '',
`comment_count` bigint(20) NOT NULL DEFAULT '0',
`views` int(99) NOT NULL,
`views_this_week` int(5) NOT NULL,
`imdb` double NOT NULL,
`imdb_votes` float NOT NULL,
`imdb_id` varchar(20) NOT NULL,
`fb_shares_root` int(5) NOT NULL,
`movie_name` varchar(140) NOT NULL,
`season` int(2) NOT NULL,
`episode` int(5) NOT NULL,
`serial_id` int(10) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Structura de tabel pentru tabelul `wphn_term_relationships`
--
CREATE TABLE IF NOT EXISTS `wphn_term_relationships` (
`object_id` bigint(20) unsigned NOT NULL DEFAULT '0',
`term_taxonomy_id` bigint(20) unsigned NOT NULL DEFAULT '0',
`term_order` int(11) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Structura de tabel pentru tabelul `wphn_term_taxonomy`
--
CREATE TABLE IF NOT EXISTS `wphn_term_taxonomy` (
`term_taxonomy_id` bigint(20) unsigned NOT NULL,
`term_id` bigint(20) unsigned NOT NULL DEFAULT '0',
`taxonomy` varchar(32) NOT NULL DEFAULT '',
`description` longtext NOT NULL,
`parent` bigint(20) unsigned NOT NULL DEFAULT '0',
`count` bigint(20) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Indexes for dumped tables
--
--
-- Indexes for table `wphn_posts`
--
ALTER TABLE `wphn_posts`
ADD PRIMARY KEY (`ID`),
ADD KEY `post_name` (`post_name`(191)),
ADD KEY `type_status_date` (`post_type`,`post_status`,`post_date`,`ID`),
ADD KEY `post_parent` (`post_parent`),
ADD KEY `post_author` (`post_author`),
ADD KEY `serial_id` (`serial_id`),
ADD KEY `episode` (`episode`),
ADD KEY `season` (`season`),
ADD KEY `movie_name` (`movie_name`);
--
-- Indexes for table `wphn_term_relationships`
--
ALTER TABLE `wphn_term_relationships`
ADD PRIMARY KEY (`object_id`,`term_taxonomy_id`),
ADD KEY `term_taxonomy_id` (`term_taxonomy_id`),
ADD KEY `term_order` (`term_order`);
--
-- Indexes for table `wphn_term_taxonomy`
--
ALTER TABLE `wphn_term_taxonomy`
ADD PRIMARY KEY (`term_taxonomy_id`),
ADD UNIQUE KEY `term_id_taxonomy` (`term_id`,`taxonomy`),
ADD KEY `taxonomy` (`taxonomy`),
ADD KEY `parent` (`parent`),
ADD KEY `count` (`count`),
ADD KEY `term_id` (`term_id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `wphn_posts`
--
ALTER TABLE `wphn_posts`
MODIFY `ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `wphn_term_taxonomy`
--
ALTER TABLE `wphn_term_taxonomy`
MODIFY `term_taxonomy_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT;
/*!40101 SET CHARACTER_SET_CLIENT=#OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=#OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=#OLD_COLLATION_CONNECTION */;
"Rows examined" = 420K -- That smacks of a missing index.
Probably missing:
INDEX(term_taxonomy_id, object_id)
Please provide SHOW CREATE TABLE for the two tables.
What is the value of innodb_buffer_pool_size?

Getting a Cannot add Foreign Key Constraint MySQL

I am having some trouble with phpMyAdmin and MySQL. All of the tables load just fine except for the order table. No matter if I do it all at once, or one table at a time, I get a #1215 - Cannot add foreign key constraint.
This happens for the Orders table only and the Customer_Number attribute. What in the world am I missing here. Thanks in advance.
-- phpMyAdmin SQL Dump
-- version 4.2.11
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Apr 19, 2015 at 01:22 AM
-- Server version: 5.6.21
-- PHP Version: 5.6.3
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
SET foreign_key_checks=0;
/*!40101 SET #OLD_CHARACTER_SET_CLIENT=##CHARACTER_SET_CLIENT */;
/*!40101 SET #OLD_CHARACTER_SET_RESULTS=##CHARACTER_SET_RESULTS */;
/*!40101 SET #OLD_COLLATION_CONNECTION=##COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
-- Database: `popcorn`
-- --------------------------------------------------------
-- Table structure for table `customer`
CREATE TABLE IF NOT EXISTS `customer` (
`Scout_Number` int(10) NOT NULL,
`Customer_Number` int(10) NOT NULL,
`Fname` varchar(15) NOT NULL,
`Lname` varchar(15) NOT NULL,
`House_Number` int(7) NOT NULL,
`Street` varchar(15) NOT NULL,
`City` varchar(15) NOT NULL,
`State` char(2) NOT NULL,
`Zip` int(5) NOT NULL,
`Phone` int(10) NOT NULL,
`Email` varchar(30) NOT NULL,
PRIMARY KEY (Scout_Number, Customer_Number)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
-- Table structure for table `den`
CREATE TABLE IF NOT EXISTS `den` (
`Den_Number` int(3) NOT NULL,
`User_Name` varchar(8) NOT NULL,
`Fname` varchar(15) NOT NULL,
`Lname` varchar(15) NOT NULL,
`Phone` int(10) NOT NULL,
`Email` varchar(30) NOT NULL,
`Den_City` varchar(15) NOT NULL,
`Sales_Goal` int(10) NOT NULL,
`Den_Sales_Total` decimal(10,2) NOT NULL,
`Den_State` char(2) NOT NULL,
PRIMARY KEY (Den_Number)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- Dumping data for table `den`
-- Table structure for table `order`
CREATE TABLE IF NOT EXISTS `order` (
`Order_Number` int(10) NOT NULL,
`Customer_Number` int(10) NOT NULL,
`Donation` decimal(5,2) NOT NULL,
`Order_Total` decimal(5,2) NOT NULL,
`Payment_Status` char(1) NOT NULL,
`Payment_Type` varchar(10) NOT NULL,
`Date` date NOT NULL,
`Delivery_Status` char(1) NOT NULL,
PRIMARY KEY (Order_Number),
FOREIGN KEY (Customer_Number) REFERENCES customer(Customer_Number)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
-- Table structure for table `order_product`
CREATE TABLE IF NOT EXISTS `order_product` (
`Order_Number` int(10) NOT NULL,
`Product_Number` int(10) NOT NULL,
PRIMARY KEY (Order_Number, Product_Number)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
-- Table structure for table `product`
CREATE TABLE IF NOT EXISTS `product` (
`Product_Number` int(10) NOT NULL,
`Product_Name` varchar(15) NOT NULL,
`Description` text NOT NULL,
`Image` blob NOT NULL,
`Price` decimal(5,2) NOT NULL,
PRIMARY KEY (Product_Number)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
-- Table structure for table `scout`
CREATE TABLE IF NOT EXISTS `scout` (
`Scout_Number` int(10) NOT NULL,
`User_Name` char(8) NOT NULL,
`Fname` varchar(15) NOT NULL,
`Lname` varchar(15) NOT NULL,
`Sales_Goal` decimal(10,2) NOT NULL,
`Prize_Progress` int(10) NOT NULL,
`Den_Number` int(3) NOT NULL,
PRIMARY KEY (Scout_Number),
FOREIGN KEY (Den_Number) REFERENCES den(Den_Number)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET CHARACTER_SET_CLIENT=#OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=#OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=#OLD_COLLATION_CONNECTION */;
Columns referenced in a foreign key have to be indexed. You don't have an index on Customer_Number in the customer table. Either change the order of the columns in the composite primary key to(Customer_Number, Scout_Number)or add an additional key just on theCustomer_Number` column.
Note, however, that having a foreign key pointing to a non-unique column is a MySQL extension to SQL, and likely to be a bad idea. See Can a foreign key reference a non-unique index?. I wonder why the primary key of the customer table isn't just Customer_Number.