MySQL布尔列没有得到更新

时间:2017-03-12 17:04:08

标签: mysql sql mysqli

给出以下行:

mysql> select * from user\G
*************************** 1. row ***************************
                   id: 1
             username: crm
             password: AAER8]HR6UnR4knR4YnRnN[]
    accountNonExpired:
     accountNonLocked:
credentialsNonExpired:
              enabled:
              created: 2017-03-12 17:40:25
          createdUser: system
          lastUpdated: NULL
      lastUpdatedUser: NULL
              visible:
              deleted:
          deletedUser: NULL
1 row in set (0.00 sec)

以下命令有效:

mysql> update user set username = 'test' where id = 1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from user\G
*************************** 1. row ***************************
                   id: 1
             username: test
             password: AAER8]HR6UnR4knR4YnRnN[]
    accountNonExpired:
     accountNonLocked:
credentialsNonExpired:
              enabled:
              created: 2017-03-12 17:40:25
          createdUser: system
          lastUpdated: NULL
      lastUpdatedUser: NULL
              visible:
              deleted:
          deletedUser: NULL
1 row in set (0.00 sec)

但是以下命令更新“可见”列不起作用:

mysql> update user set visible = true where id = 1;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 0

mysql> select * from user\G
*************************** 1. row ***************************
                   id: 1
             username: test
             password: AAER8]HR6UnR4knR4YnRnN[]
    accountNonExpired:
     accountNonLocked:
credentialsNonExpired:
              enabled:
              created: 2017-03-12 17:40:25
          createdUser: system
          lastUpdated: NULL
      lastUpdatedUser: NULL
              visible:
              deleted:
          deletedUser: NULL
1 row in set (0.00 sec)

以下是相关表格:

mysql> show create table user;
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| user  | CREATE TABLE `user` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `username` varchar(50) NOT NULL,
  `password` varchar(150) NOT NULL,
  `accountNonExpired` bit(1) DEFAULT b'1',
  `accountNonLocked` bit(1) DEFAULT b'1',
  `credentialsNonExpired` bit(1) DEFAULT b'1',
  `enabled` bit(1) DEFAULT b'0',
  `created` datetime NOT NULL,
  `createdUser` varchar(50) NOT NULL,
  `lastUpdated` datetime DEFAULT NULL,
  `lastUpdatedUser` varchar(50) DEFAULT NULL,
  `visible` bit(1) DEFAULT b'0',
  `deleted` bit(1) DEFAULT b'0',
  `deletedUser` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 |
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

这是Mysql的版本:

mysql> select version();
+-------------------------+
| version()               |
+-------------------------+
| 5.7.17-0ubuntu0.16.04.1 |
+-------------------------+
1 row in set (0.00 sec)

为什么我不能更新用户表的布尔列?

编辑:以下作品:

mysql> update user set visible = true where id = 1;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from user where id = 1\G
*************************** 1. row ***************************
                   id: 1
             username: test
             password: AAER8]HR6UnR4knR4YnRnN[]
    accountNonExpired:
     accountNonLocked:
credentialsNonExpired:
              enabled:
              created: 2017-03-12 17:40:25
          createdUser: system
          lastUpdated: NULL
      lastUpdatedUser: NULL
              visible:
              deleted:
          deletedUser: NULL
1 row in set (0.00 sec)

但是呢?没有“可见”值为true或1?

的直观表示

2 个答案:

答案 0 :(得分:0)

尝试将01列更新为false&分别为true。列的类型为bit,默认为0

答案 1 :(得分:0)

如果可见的值已经是" TRUE"" 当您执行以下操作时会发生什么?

如果您输入以下内容并且有效,那么就有答案

  

块引用

更新用户设置visible = false,其中id = 1;