Importing SQL file "Duplicate entry '0' for key 'PRIMARY'" - mysql

I know there is similar questions that are answered but please try to help me out.
I'm importing a backup of my MyBB database into a new host using PHPMyAdmin. When trying to import the .sql file, I get the following error:
SQL query:
INSERT INTO mybb_datacache( `title` , `cache` )
VALUES (
'internal_settings', 'a:1:{s:14:\"encryption_key\";s:32:\"rrvohvVATtOauucNTmEXAmvNvbw9ujvb\";}'
);
MySQL said:
#1062 - Duplicate entry 'internal_settings' for key 'PRIMARY'
I can't figure out the problem. I emptied all tables and clean install of the database four times already. I've been trying to figure this out all day and it's very frustrating.
(link removed)
Please help me out. How do I fix this problem?

When you export your sql from php admin
Select "custom" as export method"
then, instead of 'insert', choose "update"
This will perform update-statements and prevent duplicated inserts.

Make sure the column set as your PRIMARY KEY is set to AUTO_INCREMENT

From the current version of the question, it appears that the title column of the mybb_datacache table is the Primary Key and already has a record with the value 'internal_settings' in it. If this is indeed the case, then the problem is that all records must have unique values for their Primary Key.

I had this problem, and i found what the problem is.
The thing is that, the field cannot be empty. ie, if you are altering a table to add primary key, make sure you have some values in that field. or if u are importing a sql file, make sure that that field in the file has some values....
this solved my problem...

Related

MySQL Database Upload Error

My query relates to a WordPress website, which is hosted on a VPS.
Earlier today, I needed to upload my backed up Database. Upon completion, I was returned with the message:
SQL query:
ALTER TABLE 'wp_options'
ADD PRIMARY KEY ('option_id)
ADD UNIQUE KEY 'option_name' ('option_name')
MySQL said:
#1062 - Duplicate entry '0' for key 'PRIMARY'
The website seems to have fully uploaded, with all of its content, however (and I am not sure if this is connected) when I edit a page and select 'Update', it does not seem to save the modifications.
I am hoping that by resolving the database issue, the other issue will look after itself.
If anyone could provide me with a straight forward fix, it would be much appreciated.
Thanks.
Craig
Maybe you need auto incrément on primary key
MySQL doc say :
To start with an AUTO_INCREMENT value other than 1, set that value with CREATE TABLE or ALTER TABLE, like this:
mysql> ALTER TABLE tbl AUTO_INCREMENT = 100;

MySQL error 1215: Can not add foreign key constraint

I am trying to forward engineer my new schema onto my db server, but I can't figure out why I am getting this error. I've tried to search for the answer here, but nothing I've tried worked.
This is the error I get when I am trying to forward engineer my new schema onto my DB server:
Few things might cause an issue:
1) Check what data types are studentnummer column in student table and vakID in vakklas - Are they INT and VARCHAR(45)?
2) Check for typing errors - are tables and columns you're referencing named same way as in this CREATE statement?
3) Check if student and vakklas already have some rows that violate NOT NULL condition - is there a record with NULL value in referenced columns?
4) Are you using InnoDB for all tables?
5) Are you sure charset is the same on all tables? This is important especially because you're using VARCHAR as foreign key. Try adding DEFAULT CHARSET=utf8 after ENGINE = InnoDB on all queries for table creating - it might solve the problem

MySQL: making a column unique?

I have a table that is in production. I realize that some of the columns should be unique. Is it safe to go into phpMyAdmin and change those columns to make it unique?
ALTER TABLE `foo` ADD UNIQUE ( `bar` )
Follow the below steps to apply unique column value from phpmyadmin panel:
Go to the table structure. Click on the unique keyword as like below -
Click on the ok from confirmation box -
Unique value constraint for column will apply.
Or you can run mysql query:
ALTER TABLE user ADD UNIQUE(email);
You do not have duplicates -> will apply the key without issues
You do have duplicates -> will give an error message, nothing happened to your data
All is unique, except several rows with NULL in them, unique constraint is still applied, as NULL is not checked when checking for unique values (you can have the entire table have a NULL value in a unique field without any error message).
One more thing, if you have a prod DB, you must also have a dev DB which you can test on without fear, right?
If there are already some duplicate values in those columns, then this will generate an error. If there aren't any duplicate values in those columns, then you will be fine.
It will only be a problem if the pre-existing values on the table are not unique, otherwise I don't think there will be any problem.
I had this problem and my values were not unique. I also couldn't find an easy way to edit this problem in PHPMyAdmin. Here's how I solved it:
I clicked into the table I needed to update
I exported the table, changing it to be a CSV export and then edited
it manually to update the non-unique values.
Making sure I was still in the table I had exported (because I
wanted to keep the headers intact), I imported my newly saved CSV
Hope that saves someone some time in the future.

phpMyAdmin: MySQL Error 1062 - Duplicate entry

I connect with user "root" onto my database "test" which I host locally for development. Among others I have the table "ratingcomment". For some reason when I click on the table "ratingcomment" phpMyAdmin shows me the following error:
Fehler
SQL-Befehl:
INSERT INTO `phpmyadmin`.`pma_history` (
`username` ,
`db` ,
`table` ,
`timevalue` ,
`sqlquery`
)
VALUES (
'root', 'test', 'ratingcomment', NOW( ) , 'SELECT * FROM `ratingcomment`'
)
MySQL meldet:
#1062 - Duplicate entry '838' for key 'PRIMARY'
I used google to finde out the following
"This indicates that you have a UNIQUE or PRIMARY index on a table, and there is a duplicate value someone on one of the values in one of these indexes."
But I still dont quite understand the error! I use a primary Key, which auto-increments for all of my tables, so there actually shouldnt be a problem with the table. I had another table named "rating" which had a column "comment". Can it be, that this causes problems?
Quick fix:
REPAIR TABLE `phpmyadmin`.`pma_history`
If that fails, I'd just truncate/empty the table.
TRUNCATE TABLE `phpmyadmin`.`pma_history`
Although phpmyadmin has it's place in my toolbox, I personally don't use it's internal db.
ADDENDUM
MyISAM tables can easily become corrupted. A couple causes that usually hit me: if the MySQL is not shutdown properly, or if the table has a FULLTEXT index and the stopword file on disk had changed.
Simply stated, the REPAIR just checkes the data file for errors (and depending on your options, makes it usable again) and rewrites the index file. Fair warning: with MyISAM, repairing a table can often toast all your data in that table to make it usable. See doc for more details.
A google search pertaining to this pma table being corrupted lead me to this.
This appears to be an internal error. You've issued this query:
SELECT * FROM `ratingcomment`
phpMyAdmin tries to write such action in its internal event log and it fails. If you Google for pma_history you'll find several references to such table being corrupted.
My advice is that you find another SQL client (such as HeidiSQL) and try to repair the phpMyAdmin database.
I know this is kinda late but I had the same problem and wanted to share what I did.
In PhpMyAdmin, I went to the table's Operation tab, and just incremented the AUTO_INCREMENT value under Table options and inserted a dummy record.

MySql Query Browser Updating row issue

I am unable to edit my table in MySqL Query Browser.
I have the primary key defined, but I am still unable to edit.
Is there anything else that I need?
Thanks
Things to check:
does your user have write access to this table?
does the primary key column is shown in your query?
does your query is showing fields present in only one table?