MySql - INSERT returns 0 rows affected - mysql

I'm trying to run the following command in the command line terminal of MySql, on my backup server:
Table Schema :
CREATE TABLE `cadveiculoequip` (
`idveiculoequip` VARCHAR(36) NOT NULL,
`idveiculo` VARCHAR(36) DEFAULT NULL,
`idequipamento` VARCHAR(36) DEFAULT NULL,
`datainstalacao` DATE DEFAULT NULL,
`datadesinstalacao` DATE DEFAULT NULL,
`idchkheader` VARCHAR(36) DEFAULT NULL,
`ID` INT(11) DEFAULT NULL,
`lastupdate` TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
`primario` INT(1) NOT NULL DEFAULT '1',
`mapeia_sombra` INT(1) DEFAULT '0',
`tec_responsavel` VARCHAR(100) DEFAULT NULL,
`km_rodado` VARCHAR(100) DEFAULT NULL,
`situacao` INT(2) DEFAULT NULL,
`teclado` VARCHAR(36) DEFAULT NULL,
`rfid` VARCHAR(36) DEFAULT NULL,
`idsatelite` VARCHAR(36) DEFAULT NULL,
`telemetria` VARCHAR(10) DEFAULT NULL,
`idosdes` VARCHAR(36) DEFAULT NULL,
PRIMARY KEY (`idveiculoequip`)
) ENGINE=INNODB DEFAULT CHARSET=utf8 AVG_ROW_LENGTH=129;
Query is :
INSERT INTO `cadveiculoequip` (`idveiculoequip`,`idveiculo`,`idequipamento`,`datainstalacao`,`datadesinstalacao`,`idchkheader`,`ID`,`lastupdate`,`primario`,`mapeia_sombra`,`tec_responsavel`,`km_rodado`,`situacao`,`teclado`,`rfid`,`idsatelite`,`telemetria`,`idosdes`)
VALUES ('IGORM','6788103A-8109-430C-A131-9FBBAF6D01F3','8abef011-c107-11df-b983-68b5558ab3e2','2018-02-21',NULL,'2CA923B6-60E9-42CF-BCFB-4BA238263079',4257329,'2018-02-21 08:44:51',1,0,'IGORM','0',1,NULL,NULL,NULL,'',NULL);
After execute the command, i just receive the message "0 rows affected".
Okay, so what's the problem..? I have executed the exactly same command in my development server (identical to backup server) the command has executed successfully, besides has returned "1 rows affected".
I discard the idea of ​​being a MySQL Error 1064.. Does anyone know what it could be?
(Sorry about the bad english, I'm kind of rusty... hehehe)
Edit:
Table 'cadveiculoequip'

Related

MySQL acting as bottleneck with multiple INSERT (NodeJS)

I am trying to process a huge CSV file (650 million rows) row by row using NodeJS and then inserting the rows in a MySQL database. I keep in memory sets of 5000 rows and then I perform a multiple INSERT on the database (INSERT INTO tableName (field1,field2) VALUES ('a','a'),('b','b')...)
When launching the script it works pretty well (5000 rows are inserted each 1.5 seconds approximately). However, when 6 million rows have been processed and inserted, the INSERTs start to take about 8-9 seconds, slowing down the process.
What could be happening? Is the MySQL server acting as bottleneck? Any ideas?
Thanks in advance.
UPDATE: This is the CREATE TABLE:
sips2consumo_20200826 | CREATE TABLE `sips2consumo_20200826` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`field1` varchar(22) NOT NULL,
`field2` varchar(10) NOT NULL,
`field3` varchar(10) NOT NULL,
`field4` varchar(3) NOT NULL,
`field5` int(11) DEFAULT NULL,
`field6` int(11) DEFAULT NULL,
`field7` int(11) DEFAULT NULL,
`field8` int(11) DEFAULT NULL,
`field9` int(11) DEFAULT NULL,
`field10` int(11) DEFAULT NULL,
`field11` int(11) DEFAULT NULL,
`field12` int(11) DEFAULT NULL,
`field13` int(11) DEFAULT NULL,
`field14` int(11) DEFAULT NULL,
`field15` int(11) DEFAULT NULL,
`field16` int(11) DEFAULT NULL,
`field17` int(11) DEFAULT NULL,
`field18` int(11) DEFAULT NULL,
`field19` int(11) DEFAULT NULL,
`field20` int(11) DEFAULT NULL,
`field21` int(11) DEFAULT NULL,
`field22` int(11) DEFAULT NULL,
`field23` varchar(1) DEFAULT NULL,
`field24` varchar(2) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `unique_consumption` (`field1`,`field2`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4
Depends on how you are using mysql, most probably you are creating connections every time, you need to create connection once and insert data in batches as you are doing with 5000 rows a time and when completed close the connection,
Also it is good practice to keep your counter (last row inserted) persistent somewhere so in case of failure you don't start from 0th row, instead continue from the last inserted row before failure.

MySQL Import CSV (Row import failed with error: ("Incorrect datetime value: '' for column 'Escalation_date' at row 1", 1292)

I've exported some rows from a table in order to simulate a Import from CSV into MySQL Table.
Rows are like this:
Number;Opened;Opened by;Source;Caller;Location;Category;Subcategory;Priority;Incident state;On hold reason;Assignment group;Support vendor name;ID vendor ticket;Escalation date;Parent Incident;Problem;Resolved;Resolved by;Closed;Closure CI;CI Closure Code;Sub CI;Sub Closure CI;Resolve time;Duration
INC0028837;2019-01-02 07:01:35;User1;Portal;User2;Location1;Category1;Sub_Cat1;3 - Moderate;Closed;;Assignment1;;;;;;2019-01-02 09:43;Resolved1;2019-01-05 10:00:00;;;;;9742;9742
I made some stored procedure that will update last columns when called.
My DB structure is as follows:
CREATE TABLE `incident_raw_data` (
`Number` varchar(12) NOT NULL,
`Opened` datetime DEFAULT NULL,
`Opened_by` varchar(45) DEFAULT NULL,
`Source` varchar(12) DEFAULT NULL,
`Caller` varchar(25) DEFAULT NULL,
`Location` varchar(25) DEFAULT NULL,
`Category` varchar(45) DEFAULT NULL,
`Subcategory` varchar(25) DEFAULT NULL,
`Priority` varchar(12) DEFAULT NULL,
`Incident_state` varchar(12) DEFAULT NULL,
`On_hold_reason` varchar(255) DEFAULT NULL,
`Assignment_group` varchar(45) DEFAULT NULL,
`Support_vendor_name` varchar(5) DEFAULT NULL,
`ID_vendor_ticket` varchar(25) DEFAULT NULL,
`Escalation_date` datetime DEFAULT NULL,
`Parent_Incident` varchar(12) DEFAULT NULL,
`Problem` varchar(255) DEFAULT NULL,
`Resolved` datetime DEFAULT NULL,
`Resolved_by` varchar(45) DEFAULT NULL,
`Closed` datetime DEFAULT NULL,
`Closure_CI` varchar(45) DEFAULT NULL,
`CI_Closure_Code` varchar(5) DEFAULT NULL,
`Sub_CI` varchar(12) DEFAULT NULL,
`Sub_Closure_CI` varchar(255) DEFAULT NULL,
`Resolve_time` int(11) NOT NULL,
`Duration` int(11) NOT NULL,
`Opened_weekeday` int(11) NOT NULL,
`Resolved_weekeday` int(11) NOT NULL,
`Closed_weekday` int(11) NOT NULL,
`Opened_hour` int(11) NOT NULL,
`Aging` int(11) NOT NULL,
`Gruppo_creatore` varchar(12) DEFAULT NULL,
`Gruppo_risolutore` varchar(12) DEFAULT NULL,
`Check_SSG/SSG` tinyint(1) DEFAULT NULL,
`Aging_<5` tinyint(1) DEFAULT NULL,
`Aging_hh` double DEFAULT NULL,
PRIMARY KEY (`Number`),
KEY `Resolve_time_index` (`Resolve_time`),
KEY `Duration_index` (`Duration`),
KEY `Opened_weekeday_index` (`Opened_weekeday`),
KEY `Resolved_weekeday_index` (`Resolved_weekeday`),
KEY `Closed_weekday_index` (`Closed_weekday`),
KEY `Opened_hour_index` (`Opened_hour`),
KEY `Aging_index` (`Aging`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
Table B has the same structure in order not to tamper with original data and to perform some tests.
When I use the Import Wizard from Workbech, everything is correct except that when I've a EMPTY value in field Escalation_date, wizard tells me:
(Row import failed with error: ("Incorrect datetime value: '' for
column 'Escalation_date' at row 1", 1292)
I've disabled STRICT_MODE both global and session(SET ##global.sql_mode = '';), but still import fails.
I've also tried to modify the csv, putting '0000-00-00 00:00:00' in the corresponding column, but i get the same error.
So i failed to understand which is the correct way to import this csv file.
Where am i wrong?
I had this similar problem, discovering that MySQL DATETIME fields in particular don't like CSV empty values. I ended up working around it by replacing ,, with ,NULL, within the CSV file.

MySQL issue with altering column to add default

I have a table named Users with a column call created. Whenever a record is created I want to add the datetime.
Users Table:
CREATE TABLE `Users` (
`userId` int(11) unsigned NOT NULL AUTO_INCREMENT,
`fullName` varchar(50) DEFAULT NULL,
`firstName` varchar(25) NOT NULL DEFAULT '',
`lastName` varchar(25) NOT NULL DEFAULT '',
`address` varchar(50) NOT NULL DEFAULT '',
`city` varchar(25) DEFAULT NULL,
`state` char(2) DEFAULT NULL,
`zipCode` varchar(25) DEFAULT NULL,
`email` varchar(50) NOT NULL DEFAULT '',
`cellPhone` varchar(15) DEFAULT NULL,
`birthDate` date NOT NULL,
`creditCard` varchar(250) NOT NULL DEFAULT '',
`subscriptionStarted` date NOT NULL,
`subscriptionEnded` date NOT NULL,
`basicPlan` tinyint(1) DEFAULT NULL,
`standardPlan` tinyint(1) DEFAULT NULL,
`premiumPlan` tinyint(1) DEFAULT NULL,
`staff` tinyint(1) DEFAULT NULL,
`admin` tinyint(1) DEFAULT NULL,
`systemAdmin` tinyint(1) DEFAULT NULL,
`edited` datetime DEFAULT NULL,
`created` datetime DEFAULT NULL,
PRIMARY KEY (`userId`)
) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=latin1;
now i added this extra query to make my created field get the current datetime when a new record is created.
ALTER TABLE Users
ALTER COLUMN created SET DEFAULT CURRENT_TIMESTAMP
The problem is that I get the following error when running the alter table query
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 'CURRENT_TIMESTAMP' at line 2
Your syntax is slightly off, I think you have to specify the column to change:
ALTER TABLE Users CHANGE created created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
See this sample SQL Fiddle for an example.

MySQL delete data without query?

I have a client that is describing an occurrence when they are adding new data from a web form. If the submitted data matches any existing database entries, the system deletes the existing entry.
I've checked the scripts and I don't see a DELETE query that would affect the related table. There are UPDATE queries, none of which affect a field in the DB indicating a deletion or marked as deleted.
Are there ways data could be lost without the execution of a DELETE query?
As asked for, here's the "create table" statement:
CREATE TABLE `msp_zip_codes`
(
`zip_code` varchar(5) DEFAULT NULL,
`city` varchar(35) DEFAULT NULL,
`state_prefix` varchar(2) DEFAULT NULL,
`county` varchar(45) DEFAULT NULL,
`area_code` varchar(45) DEFAULT NULL,
`CityType` varchar(1) DEFAULT NULL,
`CityAliasAbbreviation` varchar(13) DEFAULT NULL,
`CityAliasName` varchar(35) DEFAULT NULL,
`lat` decimal(18,6) DEFAULT NULL,
`lon` decimal(18,6) DEFAULT NULL,
`time_zone` varchar(7) DEFAULT NULL,
`Elevation` int(10) DEFAULT NULL,
`CountyFIPS` varchar(5) DEFAULT NULL,
`DayLightSaving` varchar(1) DEFAULT NULL,
`PreferredLastLineKey` varchar(25) DEFAULT NULL,
`ClassificationCode` varchar(2) DEFAULT NULL,
`MultiCounty` varchar(1) DEFAULT NULL,
`StateFIPS` varchar(2) DEFAULT NULL,
`CityStateKey` varchar(6) DEFAULT NULL,
`CityAliasCode` varchar(5) DEFAULT NULL,
`PrimaryRecord` varchar(50) DEFAULT NULL,
`CityMixedCase` varchar(50) DEFAULT NULL,
`CityAliasMixedCase` varchar(50) DEFAULT NULL,
KEY `AreaCode` (`area_code`),
KEY `CityAliasCode` (`CityAliasCode`),
KEY `CityStateKey` (`CityStateKey`),
KEY `ClassificationCode` (`ClassificationCode`),
KEY `PreferredLastLineKey` (`PreferredLastLineKey`),
KEY `ZipCode` (`zip_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
One of the possibilities is that the table has an UPDATE TRIGGER set which fires every time there's an update. Or the other one, there's an Event Scheduler running on the server.
Code to show all triggers on the database:
SELECT *
FROM INFORMATION_SCHEMA.TRIGGERS a
WHERE a.TRIGGER_SCHEMA LIKE CONCAT('%', 'databaseNameHERE', '%')
Code to show all events on the database:
SHOW EVENTS FROM databaseNameHERE;

Query executing but no results

I'm trying to execute the following query via the "Run SQL query/queries on database" page in phpmyadmin:
CREATE TABLE IF NOT EXISTS `bindings` (
`binding_id` int(10) unsigned NOT NULL auto_increment,
`game_id` smallint(5) unsigned NOT NULL,
`layout_id` tinyint(3) unsigned NOT NULL,
`key_number` tinyint(3) unsigned NOT NULL,
`normal_action` varchar(128) default NULL,
`normal_group` tinyint(2) unsigned default NULL,
`shift_action` varchar(64) default NULL,
`shift_group` tinyint(2) unsigned default NULL,
`ctrl_action` varchar(64) default NULL,
`ctrl_group` tinyint(2) unsigned default NULL,
`alt_action` varchar(64) default NULL,
`alt_group` tinyint(2) unsigned default NULL,
`altgr_action` varchar(64) default NULL,
`altgr_group` tinyint(2) unsigned default NULL,
`extra_action` varchar(64) default NULL,
`extra_group` tinyint(2) unsigned default NULL,
`image_file` varchar(256) default NULL,
PRIMARY KEY (`binding_id`),
KEY `fk_layout_id` (`layout_id`),
KEY `fk_game_id` (`game_id`),
KEY `idx_combined_bindings` (`game_id`,`layout_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=11150 ;
The result is a green box and checkmark saying the query was executed successfully. However phpmyadmin still reports "No tables found in database". What is wrong with the query or the database? Thanks!
Note: the above query is part of a much larger dump that I want to import into the database.
Never mind. I dropped the database and started over with a blank one and everything is running fine now. Somehow things got messed up when my web host upgraded from mySQL 5.0.92 to mySQL 5.1.63. Sorry!