Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql can't create table named ‘user’

Tags:

mysql

enter image description here

but I used NetBeans,then I can create table user.

enter image description here

like image 768
Guolanren Avatar asked Dec 22 '25 01:12

Guolanren


1 Answers

User is a Keyword. If you want to use as Tablename you must put it in backticks like.

CREATE TABLE `user` ( ....

sample

mysql> CREATE TABLE `user` (
    ->   `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
    ->   `userName` varchar(32) DEFAULT NULL,
    ->   `password` varchar(32) DEFAULT NULL,
    ->   `realName` varchar(32) DEFAULT NULL,
    ->   PRIMARY KEY (`id`)
    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0,02 sec)

mysql> insert into `user` (id) VALUE (99);
Query OK, 1 row affected (0,00 sec)

mysql> select * from `user`;
+----+----------+----------+----------+
| id | userName | password | realName |
+----+----------+----------+----------+
| 99 | NULL     | NULL     | NULL     |
+----+----------+----------+----------+
1 row in set (0,00 sec)

mysql>
like image 142
Bernd Buffen Avatar answered Dec 23 '25 17:12

Bernd Buffen