Joomla 2.5 duplicate session error "PRIMARY' SQL=INSERT INTO" - mysql

This is the message we're receiving on the frontend
Duplicate entry '5dcf22giahsklj52uhukcdc6k5' for key 'PRIMARY' SQL=INSERT INTO `kawt1_session` (`session_id`, `client_id`, `time`) VALUES ('5dcf22giahsklj52uhukcdc6k5', 0, '1615520883')
I've tried truncating the sessions table, dropping the table and then creating a new structure with the following code
+++===============
CREATE TABLE IF NOT EXISTS `kawt1_session` (
`username` varchar(150) default '',
`time` varchar(14) default '',
`session_id` varchar(200) NOT NULL default '0',
`guest` tinyint(4) default '1',
`userid` int(11) default '0',
`usertype` varchar(50) default '',
`gid` tinyint(3) unsigned NOT NULL default '0',
`client_id` tinyint(3) unsigned NOT NULL default '0',
`data` longtext,
PRIMARY KEY (`session_id`(64)),
KEY `whosonline` (`guest`,`usertype`),
KEY `userid` (`userid`),
KEY `time` (`time`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
===============+++

Go to the database and find for the jos_session table ( here "jos" is prefix so you can search with your prefix and _session table )
Select that table and Repair it, it will solve the issue. https://prnt.sc/10jrzg7

As I discovered the issue was ONLY displayed on the homepage of the website, I switched the default home page to another menu item. This resolved the problem. Now I have to understand why this only occurred on the home page.

Related

Prevent MySQL from duplicates per given project

I have this MySQL table
CREATE TABLE `d_hits` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`projectId` varchar(36) NOT NULL,
`data` text CHARACTER SET utf8,
`extras` text,
`status` varchar(50) NOT NULL DEFAULT 'notDone',
`evaluation` varchar(50) DEFAULT 'NONE',
`isGoldenHIT` tinyint(1) DEFAULT '0',
`goldenHITResultId` int(11) unsigned DEFAULT '0',
`notes` text,
`created_timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`isURL` tinyint(4) DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3561574 DEFAULT CHARSET=latin1;
My goal here is to prevent the database from creating duplicates data for a given project. For example, project with projectID: 123 has data: link1 but if I enter data: link1 again it should prevent it from entering. However if projectID is 333 and the given data is again link1, it should insert it without any problems. My question is, how can I prevent the duplicates per project?
You seem to want a unique constraint.
ALTER TABLE d_hits
ADD UNIQUE (projectid,
data);

Deleting All Non-Recently Updated Keys/Inserts MySQL

I'm trying to create a DELETE statement in Java where after updating and inserting all new items into the DB, it deletes any old ones that were not affected by the update.
Reasoning: I'm hosting a game where items are saved upon logging out. Items are either updated or inserted depending on whether or not their reference exists. However, it is possible that a player could have dropped an item inside the game, thus no longer having ownership of it. I need to delete the reference to this item now that the player no longer has it.
tl;dr: Trying to write a DELETE FROM WHERE NOT IN for all non-updated objects belonging to the character
Table definition:
CREATE TABLE `inventoryitems` (
`inventoryitemid` int(10) unsigned NOT NULL AUTO_INCREMENT,
`type` tinyint(3) unsigned NOT NULL,
`characterid` int(11) DEFAULT NULL,
`accountid` int(11) DEFAULT NULL,
`itemid` int(11) NOT NULL DEFAULT '0',
`inventorytype` int(11) NOT NULL DEFAULT '0',
`position` int(11) NOT NULL DEFAULT '0',
`quantity` int(11) NOT NULL DEFAULT '0',
`owner` tinytext NOT NULL,
`petid` int(11) NOT NULL DEFAULT '-1',
`flag` int(11) NOT NULL,
`expiration` bigint(20) NOT NULL DEFAULT '-1',
`giftFrom` varchar(26) NOT NULL,
PRIMARY KEY (`inventoryitemid`),
KEY `CHARID` (`characterid`),
KEY `inventorytype` (`inventorytype`),
KEY `type` (`type`),
KEY `accountid` (`accountid`)
) ENGINE=InnoDB AUTO_INCREMENT=79597880 DEFAULT CHARSET=latin1

Is it possible to import my database on another server?

I am working on a database which is placed on an online server (Linux). I had to do big changes to this database so I moved (by export then import) this database to a local one I created (Windows Server).
After working these last days on the local database I decided that the work was already done so I exported the local database and imported it to the live one but I could not. It gave me error related to foreign-key:
#1215 - Cannot add foreign key constraint
The table phpmyadmin said that was the one with some errors was printprices and these are the create tables I have for printprices and the other tables which could have some relation to the error:
CREATE TABLE `printprices` (
`STYLE` int(11) NOT NULL DEFAULT '0',
`DIFICULTAD` int(11) NOT NULL DEFAULT '0',
`NCOLORES` int(11) NOT NULL DEFAULT '0',
`PROVEEDOR` int(11) NOT NULL DEFAULT '0',
`SIZECM2MAX` int(11) NOT NULL DEFAULT '0',
`MINQ` int(11) NOT NULL,
`MAXQ` int(11) NOT NULL,
`PRECIO` decimal(5,2) DEFAULT '0.00',
`PRECIOPRV` decimal(5,2) DEFAULT '0.00',
`MINWORK` decimal(5,2) DEFAULT '0.00',
`MINWORKPRV` decimal(5,2) DEFAULT '0.00',
PRIMARY KEY (`STYLE`,`DIFICULTAD`,`NCOLORES`,`PROVEEDOR`,`SIZECM2MAX`,`MINQ`),
KEY `FK_PRINT` (`STYLE`,`DIFICULTAD`,`NCOLORES`,`PROVEEDOR`),
CONSTRAINT `FK_PRINT` FOREIGN KEY (`STYLE`, `DIFICULTAD`, `NCOLORES`, `PROVEEDOR`) REFERENCES `print` (`STYLE`, `DIFICULTAD`, `NCOLORES`, `PROVEEDOR`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8
CREATE TABLE `print` (
`STYLE` int(11) NOT NULL DEFAULT '0',
`DIFICULTAD` int(11) NOT NULL DEFAULT '0',
`NCOLORES` int(11) NOT NULL DEFAULT '0',
`PROVEEDOR` int(11) NOT NULL DEFAULT '0',
`CFC` decimal(5,2) DEFAULT '0.00',
PRIMARY KEY (`STYLE`,`DIFICULTAD`,`NCOLORES`,`PROVEEDOR`),
KEY `FK_PRINTPROV` (`PROVEEDOR`),
KEY `FK_PRINTSTYLE` (`STYLE`),
CONSTRAINT `FK_PRINTPROV` FOREIGN KEY (`PROVEEDOR`) REFERENCES `proveedores` (`CODIPRV`) ON DELETE CASCADE,
CONSTRAINT `FK_PRINTSTYLE` FOREIGN KEY (`STYLE`) REFERENCES `printstyle` (`CODISTY`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8
CREATE TABLE `printstyle` (
`CODISTY` int(11) NOT NULL AUTO_INCREMENT,
`STYLE` varchar(30) DEFAULT NULL,
PRIMARY KEY (`CODISTY`)
) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=latin1
CREATE TABLE `proveedores` (
`CODIPRV` int(11) NOT NULL AUTO_INCREMENT,
`PROVEEDOR` varchar(20) DEFAULT NULL,
`ENVIOPRICE` decimal(4,2) NOT NULL DEFAULT '0.00',
`CARTONPRICE` decimal(4,2) NOT NULL DEFAULT '0.00',
`LIMITPRICE` decimal(6,2) NOT NULL,
PRIMARY KEY (`CODIPRV`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1
I've finally found out why it wasn't working:
The problem was I was trying to upload my database on a Mysql, hosted with Linux, which is case sensitive. My foreign keys were stored on capital letter but my tables were not.
When Mysql from Linux read the file and tried to delete a table before creating it, the table wasn't deleted because the name wasn't exactly the same as it had been already stored in capital before.
The solution was to edit the export file and change all table names from lower case to capital.

MySQL INSERT results in duplicate key, but no duplicate exists

I have read through many entries that people have claimed to have this problem and they've solved their issue but none of their answers solve MY issue. I am using phpMyAdmin to update the email address of a user. The "user_email" field is marked as UNIQUE. Whenever I update the email address to his actual email, I get:
Duplicate entry 'user#example.com' for key 'user_email'
I have Analyzed, Optimized, and Repaired the table and no errors appear -- everything comes up as OK.
I have run several SQL statements to find any duplication only to find out that none exists.
I even exported the table and imported the records again. I add the indexes and try and update... duplicate entry message. Here's the table structure:
CREATE TABLE IF NOT EXISTS `users` (
`id` bigint(20) NOT NULL,
`md5_id` varchar(200) NOT NULL DEFAULT '',
`full_name` tinytext,
`user_name` varchar(200) DEFAULT NULL,
`user_email` varchar(220) DEFAULT NULL,
`user_level` tinyint(4) NOT NULL DEFAULT '1',
`pwd` varchar(220) NOT NULL DEFAULT '',
`address` text COLLATE latin1_general_ci,
`country` varchar(200) DEFAULT NULL,
`tel` varchar(200) NOT NULL DEFAULT '',
`fax` varchar(200) DEFAULT NULL,
`website` text,
`date` date NOT NULL DEFAULT '0000-00-00',
`users_ip` varchar(200) NOT NULL DEFAULT '',
`approved` int(1) NOT NULL DEFAULT '0',
`activation_code` int(10) NOT NULL DEFAULT '0',
`banned` int(1) NOT NULL DEFAULT '0',
`ckey` varchar(220) NOT NULL DEFAULT '',
`ctime` varchar(220) NOT NULL DEFAULT '',
`location` tinyint(4) NOT NULL DEFAULT '9'
) ENGINE=MyISAM AUTO_INCREMENT=210 DEFAULT CHARSET=latin1;
ALTER TABLE `users` ADD PRIMARY KEY (`id`);
MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=210;
Even now that I have REMOVED the UNIQUE index from the 'user_email' field, the error is STILL coming up. I REALLY don't understand that (Maybe something residual...? I'm just guessing).
Picture me with wads of hair in my hands. Can anyone please help?
UPDATE:
Here's the output from SHOW CREATE TABLE users
Here's the output from SHOW INDEX FROM users
Error message while editing:
Error message without using database name:
Output of: SHOW CREATE TABLE proctor.users

Mysql Append table to add columns

I like to append a table to add column but without using alert table command
e.g.
This is the table which is missing some columns.
CREATE TABLE IF NOT EXISTS `admin` (
`id` int(11) NOT NULL auto_increment,
`username` varchar(20) NOT NULL,
`passwd` varchar(40) NOT NULL,
`isActive` tinyint(1) NOT NULL default '1',
`lastVisit` datetime NOT NULL default '0000-00-00 00:00:00',
`modifyAt` datetime NOT NULL,
`createdAt` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
So if i run this query then it should automatically add missing columns into my tables
CREATE TABLE IF NOT EXISTS `admin` (
`id` int(11) NOT NULL auto_increment,
`username` varchar(20) NOT NULL,
`passwd` varchar(40) NOT NULL,
`name` varchar(100) NOT NULL,
`originalUser` tinyint(1) NOT NULL default '0',
`isActive` tinyint(1) NOT NULL default '1',
`lastVisit` datetime NOT NULL default '0000-00-00 00:00:00',
`modifyAt` datetime NOT NULL,
`createdAt` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Can this be possible to do without using alert table command ?
I understand your question as you want to add some columns to your table. Please be informed that the term row is usually related to the actual data in your table, not the columns itself. If my assumption is wrong, please clarify your question.
You cannot use CREATE TABLE for altering a table. It is there to create table,
and if it cannot create it, it will in most cases throw an error like you described. Another command exists for that reason: ALTER TABLE.
You might do it something like this.
(1) Create your table with your CREATE TABLE syntax above:
CREATE TABLE IF NOT EXISTS `admin` (
`id` int(11) NOT NULL auto_increment,
`username` varchar(20) NOT NULL,
`passwd` varchar(40) NOT NULL,
`isActive` tinyint(1) NOT NULL default '1',
`lastVisit` datetime NOT NULL default '0000-00-00 00:00:00',
`modifyAt` datetime NOT NULL,
`createdAt` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
(2) Use ALTER TABLE like this to make the modifications I think you want to have in your second statement (two more columns):
ALTER TABLE
ADD COLUMN `name` varchar(100) NOT NULL AFTER `passwd`,
ADD COLUMN `originalUser` tinyint(1) NOT NULL default '0' AFTER `name`;
Not related to your question, but I'd avoid column names like name, because if you don't escape them properly it'll throw you other errors (see reserved words).