Using the command:
CREATE TABLE IF NOT EXISTS `test`.`t1` (
`col` VARCHAR(16) NOT NULL
) ENGINE=MEMORY;
Running this twice in the MySQL Query Browser results in:
Table 't1' already exists Error 1050
I would have thought that creating the table "IF NOT EXISTS" would not throw errors. Am I missing something or is this a bug? I am running version 5.1. Thanks.
Create mysql connection with following parameter. "'raise_on_warnings': False". It will ignore the warning. e.g.
If anyone is getting this error after a Phpmyadmin export, using the the custom options and adding the "drop tables" statements cleared this right up.
I have a solution to a problem that may also apply to you. My database was in a state where a
DROP TABLE
failed because it couldn't find the table... but aCREATE TABLE
also failed because MySQL thought the table existed. (This state could easily mess with your IF NOT EXISTS clause).I eventually found this solution:
For me, without the
sudo
, I got the following error:(Running on OS X 10.6)
I had a similar Problem as @CraigWalker on debian: My database was in a state where a
DROP TABLE
failed because it couldn't find the table, but aCREATE TABLE
also failed because MySQL thought the table still existed. So the broken table still existed somewhere although it wasn't there when I looked in phpmyadmin.I created this state by just copying the whole folder that contained a database with some
MyISAM
and someInnoDB
tables(this is not recommended!)
All InnoDB tables where not visible in the new database
test
in phpmyadmin.sudo mysqladmin flush-tables
didn't help either.My solution: I had to delete the new test database with
drop database test
and copy it withmysqldump
instead:You can use the following query to create a table to a particular database in MySql.