[英]Auto increment column description in export mysql
I want to export Mysql database using PHP code as mysqldump is not available on my server. 我想使用PHP代码导出Mysql数据库,因为我的服务器上没有mysqldump。 I am able to get most of the export file creation similar to phpmyadmin export file. 我能够获得大部分类似于phpmyadmin导出文件的导出文件。 I am stuck at how to add auto increment column name and value similar to phpmyadmin export. 我被困在如何添加类似于phpmyadmin export的自动增量列名称和值。
--
-- AUTO_INCREMENT for table `event`
--
ALTER TABLE `event`
MODIFY `event_id` bigint(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=17;
One way is to find autoincrement column name, field type and it's value using different queries. 一种方法是使用不同的查询来查找自动递增的列名称,字段类型及其值。 Is there any other way. 还有其他方法吗? Let me know. 让我知道。 Thanks 谢谢
The INFORMATION_SCHEMA.COLUMNS table tells you if a column is auto_incrementing. INFORMATION_SCHEMA.COLUMNS表告诉您列是否在自动递增。
mysql> create table test.MyTable ( id int auto_increment primary key);
mysql> select * from information_schema.columns where table_schema='test'\G
*************************** 1. row ***************************
TABLE_CATALOG: def
TABLE_SCHEMA: test
TABLE_NAME: MyTable
COLUMN_NAME: id
ORDINAL_POSITION: 1
COLUMN_DEFAULT: NULL
IS_NULLABLE: NO
DATA_TYPE: int
CHARACTER_MAXIMUM_LENGTH: NULL
CHARACTER_OCTET_LENGTH: NULL
NUMERIC_PRECISION: 10
NUMERIC_SCALE: 0
DATETIME_PRECISION: NULL
CHARACTER_SET_NAME: NULL
COLLATION_NAME: NULL
COLUMN_TYPE: int(11)
COLUMN_KEY: PRI
EXTRA: auto_increment <-- here
PRIVILEGES: select,insert,update,references
COLUMN_COMMENT:
GENERATION_EXPRESSION:
SRS_ID: NULL
The value of the table's auto_increment is in INFORMATION_SCHEMA.TABLES. 表的auto_increment值在INFORMATION_SCHEMA.TABLES中。
mysql> insert into test.MyTable () values ();
mysql> select * from information_schema.tables where table_schema='test'\G
*************************** 1. row ***************************
TABLE_CATALOG: def
TABLE_SCHEMA: test
TABLE_NAME: MyTable
TABLE_TYPE: BASE TABLE
ENGINE: InnoDB
VERSION: 10
ROW_FORMAT: Dynamic
TABLE_ROWS: 1
AVG_ROW_LENGTH: 16384
DATA_LENGTH: 16384
MAX_DATA_LENGTH: 0
INDEX_LENGTH: 0
DATA_FREE: 0
AUTO_INCREMENT: 2 <-- here
CREATE_TIME: 2018-09-09 15:31:45
UPDATE_TIME: 2018-09-09 15:33:29
CHECK_TIME: NULL
TABLE_COLLATION: utf8_general_ci
CHECKSUM: NULL
CREATE_OPTIONS:
TABLE_COMMENT:
By the way, I once tried to do what you're doing, duplicate the behavior of mysqldump in pure PHP code. 顺便说一句,我曾经尝试做您正在做的事情,在纯PHP代码中复制了mysqldump的行为。 It's harder than you think. 这比您想的要难。 My effort is unfinished, and I'm not likely to work on because I don't use PHP these days. 我的工作还没有完成,我不太可能继续工作,因为这些天我不使用PHP。 You can take a look: https://github.com/billkarwin/cats-and-dogs 您可以看一下: https : //github.com/billkarwin/cats-and-dogs
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.