Slow MySQL Query "copying to tmp table", help re-writing it - mysql

This mysql query is extremely slow, when I look at the query it is "copying to tmp table". These tables are very large especially search_attribute (79 million rows) and search_attribute_values (350,000 rows)
SELECT attributenames.name, search_attribute_values.value
FROM attributenames, categorysearchattributes, search_attribute, search_attribute_values
WHERE
categorysearchattributes.attributeid = attributenames.attributeid AND categorysearchattributes.categoryid = 4800 AND
categorysearchattributes.attributeid = search_attribute.attributeid AND
search_attribute.valueid = search_attribute_values.valueid AND
attributenames.localeid = 1
GROUP BY search_attribute.valueid
Here is a picture of the EXPLAIN of the query
Here is my database schema
-- MySQL dump 10.13 Distrib 5.5.46, for debian-linux-gnu (x86_64)
--
-- Host: localhost Database:
-- ------------------------------------------------------
-- Server version 5.5.46-0ubuntu0.14.04.2
/*!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 */;
/*!40103 SET #OLD_TIME_ZONE=##TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET #OLD_UNIQUE_CHECKS=##UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET #OLD_FOREIGN_KEY_CHECKS=##FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET #OLD_SQL_MODE=##SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET #OLD_SQL_NOTES=##SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `attributenames`
--
DROP TABLE IF EXISTS `attributenames`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `attributenames` (
`attributeid` bigint(20) NOT NULL DEFAULT '0',
`name` varchar(110) NOT NULL DEFAULT '',
`localeid` int(11) NOT NULL DEFAULT '0',
KEY `attributenames_attributeID` (`attributeid`),
KEY `attributenames_localeID` (`localeid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = #saved_cs_client */;
--
-- Table structure for table `categorysearchattributes`
--
DROP TABLE IF EXISTS `categorysearchattributes`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `categorysearchattributes` (
`categoryid` int(11) NOT NULL DEFAULT '0',
`attributeid` bigint(20) NOT NULL DEFAULT '0',
`isactive` tinyint(1) NOT NULL DEFAULT '1',
KEY `caterysearchattributes_aID` (`attributeid`),
KEY `caterysearchattributes_cID` (`categoryid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = #saved_cs_client */;
--
-- Table structure for table `product`
--
DROP TABLE IF EXISTS `product`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `product` (
`productid` int(11) NOT NULL DEFAULT '0',
`manufacturerid` int(11) NOT NULL DEFAULT '0',
`isactive` tinyint(1) NOT NULL DEFAULT '1',
`mfgpartno` varchar(70) NOT NULL DEFAULT '',
`categoryid` int(11) NOT NULL DEFAULT '0',
`isaccessory` tinyint(1) NOT NULL DEFAULT '0',
`equivalency` double NOT NULL DEFAULT '0',
`creationdate` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`modifieddate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`lastupdated` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`productid`),
KEY `product_manufacturerID` (`manufacturerid`),
KEY `product_categoryID` (`categoryid`),
KEY `product_mfgPartNo` (`mfgpartno`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = #saved_cs_client */;
--
-- Table structure for table `search_attribute`
--
DROP TABLE IF EXISTS `search_attribute`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `search_attribute` (
`productid` int(11) NOT NULL DEFAULT '0',
`attributeid` bigint(20) NOT NULL DEFAULT '0',
`valueid` int(11) NOT NULL DEFAULT '0',
`localeid` int(11) NOT NULL DEFAULT '0',
`setnumber` tinyint(2) NOT NULL DEFAULT '0',
`isactive` tinyint(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`productid`,`localeid`,`attributeid`,`setnumber`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = #saved_cs_client */;
--
-- Table structure for table `search_attribute_values`
--
DROP TABLE IF EXISTS `search_attribute_values`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `search_attribute_values` (
`valueid` int(11) NOT NULL DEFAULT '0',
`value` varchar(255) NOT NULL DEFAULT '',
`absolutevalue` double NOT NULL DEFAULT '0',
`unitid` int(11) NOT NULL DEFAULT '0',
`isabsolute` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`valueid`),
KEY `search_attrval_value` (`value`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = #saved_cs_client */;
Added attributeid_valueid index

By looking at the EXPLAIN query in the picture, the table search_attribute is doing a full table scan i.e. not using indexes at all.
Adding index to valueid column of search_attribute table should make it faster. Give it a try and share your results after adding index.
ALTER TABLE `search_attribute` ADD KEY `idx_valueid` (`valueid`);
Please try the combinations of suggestions below.

Related

MySQLdump-import into DB with different Charset: from unicode_520_ci to utf8mb4_unicode_ci

Need to rework a db-dump that comes with more than 2000 lines in order to fit my MySQL-DB. the difference is the Charset. i need to go from
COLLATE=utf8mb4_unicode_520_ci
to
CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
how to do this correctly for the whole dump?
-- MySQL dump 10.13 Distrib 5.7.23-23, for Linux (x86_64)
-- Host: localhost Database: s_wp868
-- Server version 5.7.23-23
/*!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 */;
/*!40103 SET #OLD_TIME_ZONE=##TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET #OLD_UNIQUE_CHECKS=##UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET #OLD_FOREIGN_KEY_CHECKS=##FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET #OLD_SQL_MODE=##SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET #OLD_SQL_NOTES=##SQL_NOTES, SQL_NOTES=0 */;
/*!50717 SELECT COUNT(*) INTO #rocksdb_has_p_s_session_variables FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'performance_schema' AND TABLE_NAME = 'session_variables' */;
/*!50717 SET #rocksdb_get_is_supported = IF (#rocksdb_has_p_s_session_variables, 'SELECT COUNT(*) INTO #rocksdb_is_supported FROM performance_schema.session_variables WHERE VARIABLE_NAME=\'rocksdb_bulk_load\'', 'SELECT 0') */;
/*!50717 PREPARE s FROM #rocksdb_get_is_supported */;
/*!50717 EXECUTE s */;
/*!50717 DEALLOCATE PREPARE s */;
/*!50717 SET #rocksdb_enable_bulk_load = IF (#rocksdb_is_supported, 'SET SESSION rocksdb_bulk_load = 1', 'SET #rocksdb_dummy_bulk_load = 0') */;
/*!50717 PREPARE s FROM #rocksdb_enable_bulk_load */;
/*!50717 EXECUTE s */;
/*!50717 DEALLOCATE PREPARE s */;
DROP TABLE IF EXISTS `wpsu_actionscheduler_actions`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `wpsu_actionscheduler_actions` (
`action_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`hook` varchar(191) COLLATE utf8mb4_unicode_520_ci NOT NULL,
`status` varchar(20) COLLATE utf8mb4_unicode_520_ci NOT NULL,
`scheduled_date_gmt` datetime DEFAULT '0000-00-00 00:00:00',
`scheduled_date_local` datetime DEFAULT '0000-00-00 00:00:00',
`args` varchar(191) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
`schedule` longtext COLLATE utf8mb4_unicode_520_ci,
`group_id` bigint(20) unsigned NOT NULL DEFAULT '0',
`attempts` int(11) NOT NULL DEFAULT '0',
`last_attempt_gmt` datetime DEFAULT '0000-00-00 00:00:00',
`last_attempt_local` datetime DEFAULT '0000-00-00 00:00:00',
`claim_id` bigint(20) unsigned NOT NULL DEFAULT '0',
`extended_args` varchar(8000) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
PRIMARY KEY (`action_id`),
KEY `hook` (`hook`),
KEY `status` (`status`),
KEY `scheduled_date_gmt` (`scheduled_date_gmt`),
KEY `args` (`args`),
KEY `group_id` (`group_id`),
KEY `last_attempt_gmt` (`last_attempt_gmt`),
KEY `claim_id_status_scheduled_date_gmt` (`claim_id`,`status`,`scheduled_date_gmt`)
) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
/*!40101 SET character_set_client = #saved_cs_client */;
--
-- Dumping data for table `wpsu_actionscheduler_actions`
--
LOCK TABLES `wpsu_actionscheduler_actions` WRITE;
/*!40000 ALTER TABLE `wpsu_actionscheduler_actions` DISABLE KEYS */;
INSERT INTO `wpsu_actionscheduler_actions` (`action_id`, `hook`, `status`, `scheduled_date_gmt`, `scheduled_date_local`, `args`, `schedule`, `group_id`, `attempts`, `last_attempt_gmt`, `last_attempt_local`, `claim_id`, `extended_args`) VALUES (7,'action_scheduler/migration_hook','complete','2022-02-24 18:34:17','2022-02-24 18:34:17','[]','O:30:\"ActionScheduler_SimpleSchedule\":2:{s:22:\"\0*\0scheduled_timestamp\";i:1645727657;s:41:\"\0ActionScheduler_SimpleSchedule\0timestamp\";i:1645727657;}',1,1,'2022-02-24 18:34:53','2022-02-24 18:34:53',0,NULL),(8,'woocommerce_admin/stored_state_setup_for_products/async/run_remote_notifications','complete','0000-00-00 00:00:00','0000-00-00 00:00:00','[]','O:28:\"ActionScheduler_NullSchedule\":0:{}',0,1,'2022-02-24 18:40:15','2022-02-24 18:40:15',0,NULL),(9,'woocommerce_admin/stored_state_setup_for_products/async/run_remote_notifications','complete','0000-00-00 00:00:00','0000-00-00 00:00:00','[]','O:28:\"ActionScheduler_NullSchedule\":0:{}',0,1,'2022-02-24 18:40:15','2022-02-24 18:40:15',0,NULL),(10,'woocommerce_admin/stored_state_setup_for_products/async/run_remote_notifications','complete','0000-00-00 00:00:00','0000-00-00 00:00:00','[]','O:28:\"ActionScheduler_NullSchedule\":0:{}',0,1,'2022-02-24 18:41:03','2022-02-24 18:41:03',0,NULL),(11,'woocommerce_admin/stored_state_setup_for_products/async/run_remote_notifications','complete','0000-00-00 00:00:00','0000-00-00 00:00:00','[]','O:28:\"ActionScheduler_NullSchedule\":0:{}',0,1,'2022-02-24 18:41:03','2022-02-24 18:41:03',0,NULL),(12,'woocommerce_admin/stored_state_setup_for_products/async/run_remote_notifications','complete','0000-00-00 00:00:00','0000-00-00 00:00:00','[]','O:28:\"ActionScheduler_NullSchedule\":0:{}',0,1,'2022-02-24 18:41:03','2022-02-24 18:41:03',0,NULL),(13,'woocommerce_admin/stored_state_setup_for_products/async/run_remote_notifications','complete','0000-00-00 00:00:00','0000-00-00 00:00:00','[]','O:28:\"ActionScheduler_NullSchedule\":0:{}',0,1,'2022-02-24 18:41:03','2022-02-24 18:41:03',0,NULL),(14,'woocommerce_admin/stored_state_setup_for_products/async/run_remote_notifications','complete','0000-00-00 00:00:00','0000-00-00 00:00:00','[]','O:28:\"ActionScheduler_NullSchedule\":0:{}',0,1,'2022-02-24 18:41:03','2022-02-24 18:41:03',0,NULL),(15,'woocommerce_admin/stored_state_setup_for_products/async/run_remote_notifications','complete','0000-00-00 00:00:00','0000-00-00 00:00:00','[]','O:28:\"ActionScheduler_NullSchedule\":0:{}',0,1,'2022-02-24 18:41:03','2022-02-24 18:41:03',0,NULL),(16,'woocommerce_admin/stored_state_setup_for_products/async/run_remote_notifications','complete','0000-00-00 00:00:00','0000-00-00 00:00:00','[]','O:28:\"ActionScheduler_NullSchedule\":0:{}',0,1,'2022-02-24 18:41:03','2022-02-24 18:41:03',0,NULL),(17,'woocommerce_run_update_callback','complete','2022-03-15 18:00:27','2022-03-15 18:00:27','{\"update_callback\":\"wc_update_630_create_product_attributes_lookup_table\"}','O:30:\"ActionScheduler_SimpleSchedule\":2:{s:22:\"\0*\0scheduled_timestamp\";i:1647367227;s:41:\"\0ActionScheduler_SimpleSchedule\0timestamp\";i:1647367227;}',2,1,'2022-03-15 18:00:47','2022-03-15 18:00:47',0,NULL),(18,'woocommerce_run_update_callback','complete','2022-03-15 18:00:28','2022-03-15 18:00:28','{\"update_callback\":\"wc_update_630_db_version\"}','O:30:\"ActionScheduler_SimpleSchedule\":2:{s:22:\"\0*\0scheduled_timestamp\";i:1647367228;s:41:\"\0ActionScheduler_SimpleSchedule\0timestamp\";i:1647367228;}',2,1,'2022-03-15 18:00:48','2022-03-15 18:00:48',0,NULL),(19,'woocommerce_update_db_to_current_version','complete','2022-03-15 18:00:29','2022-03-15 18:00:29','{\"version\":\"6.3.1\"}','O:30:\"ActionScheduler_SimpleSchedule\":2:{s:22:\"\0*\0scheduled_timestamp\";i:1647367229;s:41:\"\0ActionScheduler_SimpleSchedule\0timestamp\";i:1647367229;}',2,1,'2022-03-15 18:00:48','2022-03-15 18:00:48',0,NULL),(20,'woocommerce_run_product_attribute_lookup_regeneration_callback','complete','2022-03-15 18:00:48','2022-03-15 18:00:48','[]','O:30:\"ActionScheduler_SimpleSchedule\":2:{s:22:\"\0*\0scheduled_timestamp\";i:1647367248;s:41:\"\0ActionScheduler_SimpleSchedule\0timestamp\";i:1647367248;}',2,1,'2022-03-15 18:00:48','2022-03-15 18:00:48',0,NULL),(21,'wc-admin_import_customers','complete','2022-03-15 18:05:24','2022-03-15 18:05:24','[1]','O:30:\"ActionScheduler_SimpleSchedule\":2:{s:22:\"\0*\0scheduled_timestamp\";i:1647367524;s:41:\"\0ActionScheduler_SimpleSchedule\0timestamp\";i:1647367524;}',3,1,'2022-03-15 18:06:48','2022-03-15 18:06:48',0,NULL);
/*!40000 ALTER TABLE `wpsu_actionscheduler_actions` ENABLE KEYS */;
UNLOCK TABLES;
I need to rework the dataset - to fit the db here - which actually works with another charset - see below
MySQL dump 10.13 Distrib 5.5.33, for Linux (x86_64)
Host: localhost Database: fsj
-- Server version 5.5.33
/*!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 */;
/*!40103 SET #OLD_TIME_ZONE=##TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET #OLD_UNIQUE_CHECKS=##UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET #OLD_FOREIGN_KEY_CHECKS=##FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET #OLD_SQL_MODE=##SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET #OLD_SQL_NOTES=##SQL_NOTES, SQL_NOTES=0 */;
-- Table structure for table `wp_postmeta`
DROP TABLE IF EXISTS `wp_postmeta`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `wp_postmeta` (
`meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`post_id` bigint(20) unsigned NOT NULL DEFAULT '0',
`meta_key` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`meta_value` longtext COLLATE utf8mb4_unicode_ci,
PRIMARY KEY (`meta_id`),
KEY `post_id` (`post_id`),
KEY `meta_key` (`meta_key`(191))
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = #saved_cs_client */;
-- Dumping data for table `wp_postmeta`
LOCK TABLES `wp_postmeta` WRITE;
/*!40000 ALTER TABLE `wp_postmeta` DISABLE KEYS */;
INSERT INTO `wp_postmeta` VALUES (1,2,'_wp_page_template','default'),(2,3,'_wp_page_template','default');
/*!40000 ALTER TABLE `wp_postmeta` ENABLE KEYS */;
Well i think that have to rework all the following statements
utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
with the following DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
in other words: i try to replace all
ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
to
ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = #saved_cs_client */;
... in the whole DB-Dump.
Conclusio: I did this - but i still have issues. How to treat the db-dump correct to get it into my MySQL-Db?!

importing table with primary auto_increment value zero to mariadb

I'm trying to import database dump into my mariaDb 10.2.6 database.
It's a Magento 2 database.
There is this table import:
# Dump of table store_website
# ------------------------------------------------------------
DROP TABLE IF EXISTS `store_website`;
CREATE TABLE `store_website` (
`website_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Website Id',
`code` varchar(32) DEFAULT NULL COMMENT 'Code',
`name` varchar(64) DEFAULT NULL COMMENT 'Website Name',
`sort_order` smallint(5) unsigned NOT NULL DEFAULT 0 COMMENT 'Sort Order',
`default_group_id` smallint(5) unsigned NOT NULL DEFAULT 0 COMMENT 'Default Group Id',
`is_default` smallint(5) unsigned DEFAULT 0 COMMENT 'Defines Is Website Default',
PRIMARY KEY (`website_id`),
UNIQUE KEY `STORE_WEBSITE_CODE` (`code`),
KEY `STORE_WEBSITE_SORT_ORDER` (`sort_order`),
KEY `STORE_WEBSITE_DEFAULT_GROUP_ID` (`default_group_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Websites';
LOCK TABLES `store_website` WRITE;
/*!40000 ALTER TABLE `store_website` DISABLE KEYS */;
INSERT INTO `store_website` (`website_id`, `code`, `name`, `sort_order`, `default_group_id`, `is_default`)
VALUES
(0,'admin','Admin',0,0,0),
(1,'my_website','MY_WEBSITE',0,1,1);
/*!40000 ALTER TABLE `store_website` ENABLE KEYS */;
UNLOCK TABLES;
This fails giving me a duplicate key 1 error. Obviously it tries to insert the value 0 as a new increment which would be 1 but that is already in the table.
This error appears even though these options are set:
/*!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 */;
/*!40014 SET #OLD_FOREIGN_KEY_CHECKS=##FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET #OLD_SQL_MODE=##SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET #OLD_SQL_NOTES=##SQL_NOTES, SQL_NOTES=0 */;
As far as I know the InnoDB engine does not support the NO_AUTO_VALUE_ON_ZERO mode. It should be supported by MyISAM though.
Note that using zero as a key in a auto_increment column is not a recommended practice, so it is advisable to avoid it. Is it an option to import the data to MyISAM-tables, do whatever to change the zero-keys to positive numbers and then switch to InnoDB?

SQL Syntax Error - Can't Import

I have been trying to import this query but it doesn't seem to work?
-- --------------------------------------------------------
-- Host: 127.0.0.1
-- Server versie: 10.1.21-MariaDB - mariadb.org binary distribution
-- Server OS: Win64
-- HeidiSQL Versie: 9.3.0.4984
-- --------------------------------------------------------
/*!40101 SET #OLD_CHARACTER_SET_CLIENT=##CHARACTER_SET_CLIENT */;
/*!40101 SET NAMES utf8mb4 */;
/*!40014 SET #OLD_FOREIGN_KEY_CHECKS=##FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET #OLD_SQL_MODE=##SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
-- Databasestructuur van gta5_gamemode_essential wordt geschreven
CREATE DATABASE IF NOT EXISTS `gta5_gamemode_essential` /*!40100 DEFAULT CHARACTER SET utf8 */;
USE `gta5_gamemode_essential`;
-- Structuur van tabel gta5_gamemode_essential.bans wordt geschreven
CREATE TABLE IF NOT EXISTS `bans` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`banned` varchar(50) NOT NULL DEFAULT '0',
`banner` varchar(50) NOT NULL,
`reason` varchar(150) NOT NULL DEFAULT '0',
`expires` datetime NOT NULL,
`timestamp` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- Data exporteren was gedeselecteerd
-- Structuur van tabel gta5_gamemode_essential.users wordt geschreven
CREATE TABLE IF NOT EXISTS `users` (
`identifier` varchar(255) CHARACTER SET utf8mb4 NOT NULL DEFAULT '',
`group` varchar(50) NOT NULL DEFAULT '0',
`permission_level` int(11) NOT NULL DEFAULT '0',
`money` double NOT NULL DEFAULT '0',
`weapons` varchar(5000) CHARACTER SET utf8 NOT NULL,
`personalvehicle` varchar(10000) CHARACTER SET utf8 NOT NULL,
`withdraw_cost` int(10) NOT NULL,
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- Data exporteren was gedeselecteerd
/*!40101 SET SQL_MODE=IFNULL(#OLD_SQL_MODE, '') */;
/*!40014 SET FOREIGN_KEY_CHECKS=IF(#OLD_FOREIGN_KEY_CHECKS IS NULL, 1, #OLD_FOREIGN_KEY_CHECKS) */;
/*!40101 SET CHARACTER_SET_CLIENT=#OLD_CHARACTER_SET_CLIENT */;
`withdraw_cost` int(10) NOT NULL, -- Remove this comma
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
users needs a PRIMARY KEY. Or maybe you are missing the PRIMARY KEY clause??

MySQL does not recognize all UTF-8 characters

I am working with MySQL server, where I need to write/read some content contains latin characters like čćšž, but for some reason my database can not store č and ć characters.
As far as I know those characters should belong inside utf8_general_ci.
I added this to my.cnf file:
[mysqld]
init_connect='SET collation_connection = utf8_general_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_general_ci
skip-character-set-client-handshake
Take a look at this picture with all encoding:
I use SOURCE command to import my database to server. Here is content of SQL dump:
SET NAMES utf8;
/*!40101 SET SQL_MODE=''*/;
/*!40014 SET #OLD_UNIQUE_CHECKS=##UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET #OLD_FOREIGN_KEY_CHECKS=##FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET #OLD_SQL_MODE=##SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET #OLD_SQL_NOTES=##SQL_NOTES, SQL_NOTES=0 */;
CREATE DATABASE /*!32312 IF NOT EXISTS*/`horoskopium` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
USE `horoskopium`;
/*Table structure for table `day` */
DROP TABLE IF EXISTS `day`;
CREATE TABLE `day` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`text` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=85 DEFAULT CHARSET=utf8;
/*Table structure for table `love` */
DROP TABLE IF EXISTS `love`;
CREATE TABLE `love` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`text` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=97 DEFAULT CHARSET=utf8;
/*Table structure for table `month` */
DROP TABLE IF EXISTS `month`;
CREATE TABLE `month` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`text` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8;
/*Table structure for table `week` */
DROP TABLE IF EXISTS `week`;
CREATE TABLE `week` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`text` text,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=49 DEFAULT CHARSET=utf8;
/*!40101 SET SQL_MODE=#OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=#OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=#OLD_UNIQUE_CHECKS */;
/*!40111 SET SQL_NOTES=#OLD_SQL_NOTES */;
How I can solve this?
You should use utfmb4. I'm pretty sure it'll fix this.
https://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8mb4.html
Utf8_general_ci or utf8mb4 or...?

Sails-mysql Oauth

i am following this tutorial to make oauth server with mongodb, and with mongodb it works fine.
But then i try to change to sails-mysql, but i am having some problems, for example if i change the connection to mysql, if i try to create new client/user it works... but then, if i want to verifi the link, it returns this error:
Error (E_UNKNOWN) :: Encountered an unexpected error
: ER_PARSE_ERROR: 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 'undefined AND `tokens`.`access_token` undefined AND `tokens`.`access_token` unde' at line 1
at Query.Sequence._packetToError (/home/mpinto/Escritorio/Guatour/oauth-server/node_modules/sails-mysql/node_modules/mysql/lib/protocol/sequences/Sequence.js:48:14)
at Query.ErrorPacket (/home/mpinto/Escritorio/Guatour/oauth-server/node_modules/sails-mysql/node_modules/mysql/lib/protocol/sequences/Query.js:83:18)
at Protocol._parsePacket (/home/mpinto/Escritorio/Guatour/oauth-server/node_modules/sails-mysql/node_modules/mysql/lib/protocol/Protocol.js:271:23)
at Parser.write (/home/mpinto/Escritorio/Guatour/oauth-server/node_modules/sails-mysql/node_modules/mysql/lib/protocol/Parser.js:77:12)
at Protocol.write (/home/mpinto/Escritorio/Guatour/oauth-server/node_modules/sails-mysql/node_modules/mysql/lib/protocol/Protocol.js:39:16)
at Socket.<anonymous> (/home/mpinto/Escritorio/Guatour/oauth-server/node_modules/sails-mysql/node_modules/mysql/lib/Connection.js:92:28)
at Socket.emit (events.js:107:17)
at readableAddChunk (_stream_readable.js:163:16)
at Socket.Readable.push (_stream_readable.js:126:10)
at TCP.onread (net.js:538:20)
--------------------
at Protocol._enqueue (/home/mpinto/Escritorio/Guatour/oauth-server/node_modules/sails-mysql/node_modules/mysql/lib/protocol/Protocol.js:135:48)
at PoolConnection.Connection.query (/home/mpinto/Escritorio/Guatour/oauth-server/node_modules/sails-mysql/node_modules/mysql/lib/Connection.js:197:25)
at __FIND__ (/home/mpinto/Escritorio/Guatour/oauth-server/node_modules/sails-mysql/lib/adapter.js:836:20)
at Object.module.exports.adapter.find (/home/mpinto/Escritorio/Guatour/oauth-server/node_modules/sails-mysql/lib/adapter.js:803:9)
at Array.async.auto.findRecords (/home/mpinto/Escritorio/Guatour/oauth-server/node_modules/sails-mysql/lib/adapter.js:1056:21)
at /home/mpinto/Escritorio/Guatour/oauth-server/node_modules/sails-mysql/node_modules/async/lib/async.js:484:38
at _each (/home/mpinto/Escritorio/Guatour/oauth-server/node_modules/sails-mysql/node_modules/async/lib/async.js:46:13)
at Object.async.auto (/home/mpinto/Escritorio/Guatour/oauth-server/node_modules/sails-mysql/node_modules/async/lib/async.js:455:9)
at __DESTROY__ (/home/mpinto/Escritorio/Guatour/oauth-server/node_modules/sails-mysql/lib/adapter.js:1053:15)
at afterwards (/home/mpinto/Escritorio/Guatour/oauth-server/node_modules/sails-mysql/lib/connections/spawn.js:84:5)
at /home/mpinto/Escritorio/Guatour/oauth-server/node_modules/sails-mysql/lib/connections/spawn.js:40:7
at Ping.onPing [as _callback] (/home/mpinto/Escritorio/Guatour/oauth-server/node_modules/sails-mysql/node_modules/mysql/lib/Pool.js:94:5)
at Ping.Sequence.end (/home/mpinto/Escritorio/Guatour/oauth-server/node_modules/sails-mysql/node_modules/mysql/lib/protocol/sequences/Sequence.js:96:24)
at Ping.Sequence.OkPacket (/home/mpinto/Escritorio/Guatour/oauth-server/node_modules/sails-mysql/node_modules/mysql/lib/protocol/sequences/Sequence.js:105:8)
at Protocol._parsePacket (/home/mpinto/Escritorio/Guatour/oauth-server/node_modules/sails-mysql/node_modules/mysql/lib/protocol/Protocol.js:271:23)
at Parser.write (/home/mpinto/Escritorio/Guatour/oauth-server/node_modules/sails-mysql/node_modules/mysql/lib/protocol/Parser.js:77:12)
at Protocol.write (/home/mpinto/Escritorio/Guatour/oauth-server/node_modules/sails-mysql/node_modules/mysql/lib/protocol/Protocol.js:39:16)
at Socket.<anonymous> (/home/mpinto/Escritorio/Guatour/oauth-server/node_modules/sails-mysql/node_modules/mysql/lib/Connection.js:92:28)
at Socket.emit (events.js:107:17)
at readableAddChunk (_stream_readable.js:163:16)
at Socket.Readable.push (_stream_readable.js:126:10)
at TCP.onread (net.js:538:20)
Details: Error: ER_PARSE_ERROR: 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 'undefined AND `tokens`.`access_token` undefined AND `tokens`.`access_token` unde' at line 1
Generated mysql script:
-- MySQL dump 10.13 Distrib 5.5.43, for debian-linux-gnu (x86_64)
--
-- Host: localhost Database: oauth
-- ------------------------------------------------------
-- Server version 5.5.43-0ubuntu0.14.04.1
/*!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 */;
/*!40103 SET #OLD_TIME_ZONE=##TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET #OLD_UNIQUE_CHECKS=##UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET #OLD_FOREIGN_KEY_CHECKS=##FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET #OLD_SQL_MODE=##SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET #OLD_SQL_NOTES=##SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `clients`
--
DROP TABLE IF EXISTS `clients`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `clients` (
`name` varchar(255) DEFAULT NULL,
`organization` varchar(255) DEFAULT NULL,
`email` varchar(255) DEFAULT NULL,
`client_id` varchar(255) DEFAULT NULL,
`client_secret` varchar(255) DEFAULT NULL,
`trust_level` varchar(255) DEFAULT NULL,
`redirect_uri` varchar(255) DEFAULT NULL,
`date_registered` varchar(255) DEFAULT NULL,
`date_verified` varchar(255) DEFAULT NULL,
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`),
UNIQUE KEY `client_id` (`client_id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = #saved_cs_client */;
--
-- Dumping data for table `clients`
--
LOCK TABLES `clients` WRITE;
/*!40000 ALTER TABLE `clients` DISABLE KEYS */;
INSERT INTO `clients` VALUES (NULL,NULL,'mpinto#estratek.com','LdjM89WLIxrKnxExtXHUcq7ViucW20Kj','pew1d XFNWpuTnTjEGhYX495DUhxtDwUH',NULL,NULL,NULL,NULL,1);
/*!40000 ALTER TABLE `clients` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `tokens`
--
DROP TABLE IF EXISTS `tokens`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `tokens` (
`access_token` varchar(255) DEFAULT NULL,
`refresh_token` varchar(255) DEFAULT NULL,
`code` varchar(255) DEFAULT NULL,
`user_id` varchar(255) DEFAULT NULL,
`expiration_date` date DEFAULT NULL,
`client_id` varchar(255) DEFAULT NULL,
`security_level` varchar(255) DEFAULT NULL,
`scope` varchar(255) DEFAULT NULL,
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = #saved_cs_client */;
--
-- Dumping data for table `tokens`
--
LOCK TABLES `tokens` WRITE;
/*!40000 ALTER TABLE `tokens` DISABLE KEYS */;
INSERT INTO `tokens` VALUES ('opSlFDZcPxrFFL0XvLWxiIsyxRZJcIcl','WIwl2x5ZbXBxXUHTC1JUlgAKDtXovPZe','qx RalLE3asf6LCQgclr8GtQ22vtgn1lb',NULL,'2015-06- 25','LdjM89WLIxrKnxExtXHUcq7ViucW20Kj',NULL,NULL,1);
/*!40000 ALTER TABLE `tokens` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `users`
--
DROP TABLE IF EXISTS `users`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `users` (
`username` varchar(255) DEFAULT NULL,
`email` varchar(255) DEFAULT NULL,
`first_name` varchar(255) DEFAULT NULL,
`last_name` varchar(255) DEFAULT NULL,
`location` varchar(255) DEFAULT NULL,
`date_registered` date DEFAULT NULL,
`date_verified` date DEFAULT NULL,
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`encrypted_password` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`),
UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = #saved_cs_client */;
--
-- Dumping data for table `users`
--
LOCK TABLES `users` WRITE;
/*!40000 ALTER TABLE `users` DISABLE KEYS */;
/*!40000 ALTER TABLE `users` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=#OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=#OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=#OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=#OLD_UNIQUE_CHECKS */;
/*!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 */;
/*!40111 SET SQL_NOTES=#OLD_SQL_NOTES */;
-- Dump completed on 2015-06-25 14:58:43
How can i fix this?
Thanks.