mysql元数据如何存储的,简单的方式来存储关于MySQL数据库的元数据

mysql元数据如何存储的,简单的方式来存储关于MySQL数据库的元数据

2023年7月19日发(作者:)

mysql元数据如何存储的,简单的⽅式来存储关于MySQL数据库的元数据Earlier today, I asked for an easy way to store a version number for the SQL table layout you are using in SQLite, and gotthe suggestion to use PRAGMA user_version. As there is no such thing as a Pragma in MySQL, I was wondering on how youwould go about this in MySQL (Except for creating a table named "META" with a column "DB-Scheme-Version").Just to repeat what I said in the linked question: I'm not looking for a way to find out which version of MySQL is installed,but to save a version nuber that tells me what version of my MySQL-Scheme I am using, without checking every table viascript.I also saw this question, but it only allows me to version single tables. Is there something similar or, preferably, easier, forwhole Databases (Since it would be no fun to query every single table seperately)? Thanks in 's SET GLOBAL would probably work, but I prefer a solution that does not reset itself every time the server rebootsand does not require SUPER Privilege and / or access to the configuration file to use. To put it short: It should work with astandard MySQL-Database that you get when you rent a small webhosting package, not the ones you get if you rent a fullserver, as you tend to have more access to those.解决⽅案There are a couple of choices, depending on the privileges that you have. The higher privileges you have, the more“elegant” the most direct route is to create a stored function, which requires the CREATE ROUTINE privilege. > CREATE FUNCTION `mydb`.DB_VERSION() RETURNS VARCHAR(15)RETURN '1.2.7.2861';Query OK, 0 rows affected (0.03 sec)mysql> SELECT `mydb`.DB_VERSION();+--------------+| DB_VERSION() |+--------------+| 1.2.7.2861 |+--------------+1 row in set (0.06 sec)If your privileges limit you to only creating tables, you can create a simple table and put the version in a default value:mysql> CREATE TABLE `mydb`.`db_version` (`version` varchar(15) not null default '1.2.7.2861');Query OK, 0 rows affected (0.00 sec)mysql> SHOW COLUMNS FROM `mydb`.`db_version`;+---------+-------------+------+-----+------------+-------+| Field | Type | Null | Key | Default | Extra |+---------+-------------+------+-----+------------+-------+| version | varchar(15) | NO | | 1.2.7.2861 | |+---------+-------------+------+-----+------------+-------+1 row in set (0.00 sec)

发布者:admin,转转请注明出处:http://www.yc00.com/xiaochengxu/1689763814a284261.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信