Schrödingers MySQL table: exists, yet it does not

后端 未结 11 1818
野趣味
野趣味 2020-11-29 23:47

I am having the weirdest error of all.

Sometimes, when creating or altering tables, I get the \'table already exists\' error. However, DROP TABLE returns \'#1051 - u

相关标签:
11条回答
  • 2020-11-30 00:13

    The fix turns out to be easy; at least what I worked out, worked for me. Create a table "zzz" on another MySQL instance, where zzz is the problem table name. (i.e. if the table is called schrodinger, substitute that for zzz whever written.) It does not matter what the definition of the table is. It's a temporary dummy; Copy the zzz.frm file to the database directory on server where the table should be, making sure file ownership and permissions are still correct on the file. On MySQL, you can now do "show tables;", and the table zzz will be there. mysql> drop table zzz; ...should now works. Clear any zzz.MYD or ZZZ.MYI files in the directory if necessary.

    0 讨论(0)
  • 2020-11-30 00:13

    In my case the problem was solved by changing the ownership of the mysql data directory to the user that ran the application. (In my case it was a Java application running Jetty webserver.)

    Even though mysql was running and other apps could use it properly, this app had a problem with that. After changing the data directory ownership and resetting the user's password, everything worked properly.

    0 讨论(0)
  • 2020-11-30 00:14

    I had this problem and hoped deleting the IBD file would help as posted above but it made no difference . MySQL only recreated a new IBD file . In my case, there are actually similar tables in other databases in the same MySQL instance . Since the FRM file was missing , I copied the FRM file from the similar table in another database , restarted MySQL and the table worked correctly .

    0 讨论(0)
  • 2020-11-30 00:19

    If will are stock with this error 1051 and you only want to delete the database and import this again do this steps and all gonna be just fine....

    in Unix envoriment AS root:

    • rm -rf /var/lib/mysql/YOUR_DATABASE;
    • OPTIONAL -> mysql_upgrade --force
    • mysqlcheck -uUSER -pPASS YOUR_DATABASE
    • mysqladmin -uUSER -pPASS drop YOUR_DATABASE
    • mysqladmin -uUSER -pPASS create YOUR_DATABASE
    • mysql -uUSER -pPASS YOUR_DATABASE < IMPORT_FILE

    Regards, Christus

    0 讨论(0)
  • 2020-11-30 00:20

    I doubt this is a direct answer to the question case here, but here is how I solved this exact perceived problem on my OS X Lion system.

    I frequently create/drop tables for some analytics jobs I have scheduled. At some point, I started getting table already exists errors half-way through my script. A server restart typically solved the issue, but that was too annoying of a solution.

    Then I noticed in the local error log file this particular line:

    [Warning] Setting lower_case_table_names=2 because file system for /usr/local/mysql/data/ is case insensitive
    

    This gave me the idea that maybe if my tables contained capital letters, MySQL would be fooled into thinking they are still there even after I had dropped them. That turned out to be the case and switching to using only lowercase letters for table names made the problem go away.

    It is likely the result of some misconfiguration in my case, but hopefully this error case will help someone waste less time trying to find a solution.

    0 讨论(0)
提交回复
热议问题