mysqlmysql-error-1146

Creating tables in MySQL


I created a table license_serial in my "database_name". But when I tried creating a second table named license, it says that it already exists.
Why is that ? My database contains only a license_serial.frm and a db.opt.

mysql> SHOW TABLES;
+---------------------+
| Tables_in_mobilemp3 |
+---------------------+
| license_serial      |
+---------------------+
1 row in set (0.00 sec)

mysql> select * from license;
ERROR 1146 (42S02): Table 'mobilemp3.license' doesn't exist

Creating the second table:

CREATE TABLE `license` (
`id` int(10) unsigned NOT NULL auto_increment,
`serial_id` int(10) unsigned NOT NULL,
`uid` bigint(20) unsigned NOT NULL,
`active` tinyint(1) NOT NULL,
`first_seen` timestamp NOT NULL default CURRENT_TIMESTAMP,
`last_seen` timestamp NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `serial_uid` (`serial_id`,`uid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

gives the following error message:

ERROR 1050 (42S01): Table 'mobilemp3.license' already exists

EDIT:

And the solution is this(in this order):

drop database databasename;
create database databasename;
use databasename;

Solution

  • The only thing I can think of, is that the table was created e.g. by root and the user you are using does not have access to that table. In that case you cannot select from it (not sure if it would be filtered out in the show tables command though)

    Log in as root to that database and check if that table exists.