MySQL “CREATE TABLE IF NOT EXISTS” -> Error 1050

后端 未结 9 1474
温柔的废话
温柔的废话 2021-02-01 00:16

Using the command:

CREATE TABLE IF NOT EXISTS `test`.`t1` (
    `col` VARCHAR(16) NOT NULL
) ENGINE=MEMORY;

Running this twice in the MySQL Que

9条回答
  •  孤城傲影
    2021-02-01 00:58

    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 a CREATE 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 some InnoDB tables

    cp -a /var/lib/mysql/sometable /var/lib/mysql/test
    

    (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 with mysqldump instead:

    mysqldump somedatabase -u username -p -r export.sql
    mysql test -u username -p < export.sql
    

提交回复
热议问题