在 MySQL 中创建表

发布于 2024-11-16 16:11:12 字数 1088 浏览 7 评论 0原文

我在我的“database_name”中创建了一个表license_serial。但是当我尝试创建第二个名为许可证的表时,它说它已经存在。
这是为什么 ?我的数据库仅包含一个license_serial.frm和一个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

创建第二个表:

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 ;

给出以下错误消息:

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

编辑:

解决方案是这样的(按此顺序):

drop database databasename;
create database databasename;
use databasename;

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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

会发光的星星闪亮亮i 2024-11-23 16:11:12

我唯一能想到的是,该表是由 root 创建的,而您使用的用户无权访问该表。在这种情况下,您无法从中进行选择(但不确定它是否会在显示表命令中被过滤掉)

以 root 身份登录到该数据库并检查该表是否存在。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文