mysql中id值重置为零_mysql-自动增量重置为0,但是不能插入id = 0的...

我偶然发现了一个非常奇怪的行为:

想象一下,我们有一个餐桌顾客:

MariaDB [connections]> describe customers;

+--------------+-------------+------+-----+---------+----------------+

| Field | Type | Null | Key | Default | Extra |

+--------------+-------------+------+-----+---------+----------------+

| customerId | int(11) | NO | PRI | NULL | auto_increment |

| customerName | varchar(50) | NO | | NULL | |

+--------------+-------------+------+-----+---------+----------------+

2 rows in set (0.00 sec)

插入几个值:

insert into customers(customerName) values('Foo');

insert into customers(customerName) values('Bar');

然后删除所有内容并重置自动增量:

DELETE FROM customers;

ALTER TABLE customers AUTO_INCREMENT = 0;

现在,插入一个带有customerId = 0的新值:

INSERT INTO customers(customerId,customerName) VALUES(0,'Site owner');

并查看结果:

MariaDB [connections]> select * from customers;

+------------+--------------+

| customerId | customerName |

+------------+--------------+

| 1 | Site owner |

+------------+--------------+

1 row in set (0.00 sec)

customerId设置为1 !!!!

重复相同的过程,但重置为5并插入5,一切正常:

MariaDB [connections]> delete from customers;

Query OK, 1 row affected (0.00 sec)

MariaDB [connections]> ALTER TABLE customers AUTO_INCREMENT = 5;

Query OK, 0 rows affected (0.00 sec)

Records: 0 Duplicates: 0 Warnings: 0

MariaDB [connections]> INSERT INTO customers(customerId,customerName) VALUES(5,'Site owner');

Query OK, 1 row affected (0.00 sec)

MariaDB [connections]> select * from customers;

+------------+--------------+

| customerId | customerName |

+------------+--------------+

| 5 | Site owner |

+------------+--------------+

1 row in set (0.00 sec)

这里发生了什么?如何插入值“ 0”和插入值? (是的,我以后可以编辑,但由于各种原因,对于我的情况而言,这是不切实际的).

谢谢!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以按照以下步骤进行mysqld_exporter与mysql8的连接: 1. 下载并解压mysqld_exporter-0.10.0.linux-amd64.tar.gz文件: ``` wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.10.0/mysqld_exporter-0.10.0.linux-amd64.tar.gz tar -zxvf mysqld_exporter-0.10.0.linux-amd64.tar.gz ``` 2. 修改mysqld_exporter的配置文件,以便连接mysql8: ``` vi mysqld_exporter-0.10.0.linux-amd64/mysqld_exporter.cnf ``` 将文件内容修改为: ``` [client] user = username password = password host = localhost port = 3306 tls_skip_verify = true ``` 其,username和password分别为mysql8的用户名和密码。 3. 启动mysqld_exporter: ``` cd mysqld_exporter-0.10.0.linux-amd64/ ./mysqld_exporter --config.my-cnf=./mysqld_exporter.cnf ``` 注意要在mysqld_exporter-0.10.0.linux-amd64目录下运行mysqld_exporter。 4. 测试是否成功连接mysql8: 在浏览器访问http://localhost:9104/metrics,如果能看到类似以下内容,则说明连接成功: ``` # HELP mysql_global_status_aborted_clients MySQL aborted clients # TYPE mysql_global_status_aborted_clients counter mysql_global_status_aborted_clients{instance="localhost:3306",job="mysql"} 0 # HELP mysql_global_status_aborted_connects MySQL aborted connects # TYPE mysql_global_status_aborted_connects counter mysql_global_status_aborted_connects{instance="localhost:3306",job="mysql"} 0 ... ``` 如果连接失败,则需要检查mysql8的用户名、密码、主机名、端口号等是否正确。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值