AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / dba / 问题 / 111227
Accepted
Chris Muench
Chris Muench
Asked: 2015-08-17 14:19:43 +0800 CST2015-08-17 14:19:43 +0800 CST 2015-08-17 14:19:43 +0800 CST

仅当我们能够对数据库进行全文搜索时才执行代码(mysql >= 5.6.4)

  • 772

我找到了关于如何为执行 mysql 语句提供条件逻辑的答案 ( https://stackoverflow.com/a/7537348/627473 )。似乎工作得很好。

但我需要找到一种方法来针对非常具体的条件执行代码。仅当数据库支持 innodb 的 FULL TEXT 索引时,代码才能执行。这发生在 mysql 5.6.4 或更高版本中。但是我也需要这个来为 maria db 的其他 mysql 分支工作。

我确定我可以找到 mysql 版本的方法;但我真的不喜欢依赖版本,而宁愿依赖功能检测。

有没有办法做到这一点?

编辑:这是代码。我只是有更多错误,我不确定是否可以修复。

在 phpMyAdmin"#2014 - Commands out of sync; you can't run this command now"中显示错误。CLI 不会发生这种情况。有没有解决的办法?

delimiter //

create procedure update_phppos() 

begin
set @supports_ft := (SELECT COUNT(*) FROM information_schema.GLOBAL_VARIABLES WHERE Variable_name = 'innodb_ft_cache_size');

if  @supports_ft > 0 then 

    REPLACE INTO `phppos_app_config` (`key`, `value`) VALUES ('version', '15.0');

    else
        SELECT 'An error has occured. You MUST have mysql 5.6.4 or higher to update php point of sale' as 'ERROR';
    end if;
end;

//

delimiter ;

-- Execute the procedure
call update_phppos();

-- Drop the procedure
drop procedure update_phppos;
mysql
  • 2 2 个回答
  • 166 Views

2 个回答

  • Voted
  1. Best Answer
    Rick James
    2015-08-17T16:42:57+08:002015-08-17T16:42:57+08:00

    计划 A: 注意如果版本早于某个版本,您可以如何注释:(我运行的是 5.6.12。)

    mysql> SELECT /*!50604 '5.6.4 is running', */ 'new or old';
    +------------------+------------+
    | 5.6.4 is running | new or old |
    +------------------+------------+
    | 5.6.4 is running | new or old |
    +------------------+------------+
    
    mysql> SELECT /*!50700 '5.7 is running', */ 'new or old';
    +------------+
    | new or old |
    +------------+
    | new or old |
    +------------+
    

    您可以在 的输出中看到很多示例mysqldump。

    B 计划:@@version您还可以在存储过程(或客户端代码)中进行 解析。

    Plan C: 或者,也许这个

    mysql> SELECT COUNT(*) FROM information_schema.GLOBAL_VARIABLES
            WHERE Variable_name = 'Junk';
    +----------+
    | COUNT(*) |
    +----------+
    |        0 |
    +----------+
    
    mysql> SELECT COUNT(*) FROM information_schema.GLOBAL_VARIABLES
          WHERE Variable_name = 'innodb_ft_cache_size';
    +----------+
    | COUNT(*) |
    +----------+
    |        1 |
    +----------+
    
    • 2
  2. Chris Muench
    2015-08-30T10:42:28+08:002015-08-30T10:42:28+08:00

    编辑:唯一的问题是它只适用于 mysql 5.7 中的 ROOT 用户。有人知道其他方法吗?

    适用于 mysql 5.5、5.6、5.7

    begin
    set @supports_ft = 0;
    set @information_schema_exists := (SELECT COUNT(SCHEMA_NAME) FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = 'information_schema');
    
    if @information_schema_exists > 0 then
        set @information_schema_exists_global_vars_exists := (SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'information_schema' AND TABLE_NAME = 'GLOBAL_VARIABLES');
            if @information_schema_exists_global_vars_exists > 0 then
                set @supports_ft := (SELECT COUNT(*) FROM information_schema.GLOBAL_VARIABLES WHERE VARIABLE_NAME = 'innodb_ft_cache_size');
            end if;
    end if;
    
    if @supports_ft = 0 then
        set @performance_schema_exists := (SELECT COUNT(SCHEMA_NAME) FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = 'performance_schema');
        if @performance_schema_exists > 0 then
            set @performance_schema_exists_global_vars_exists := (SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'performance_schema' AND TABLE_NAME = 'GLOBAL_VARIABLES');
                if @performance_schema_exists_global_vars_exists > 0 then
                    set @supports_ft := (SELECT COUNT(*) FROM performance_schema.GLOBAL_VARIABLES WHERE VARIABLE_NAME = 'innodb_ft_cache_size');
                end if;
        end if;
    end if;
    
    • 0

相关问题

  • 是否有任何 MySQL 基准测试工具?[关闭]

  • 我在哪里可以找到mysql慢日志?

  • 如何优化大型数据库的 mysqldump?

  • 什么时候是使用 MariaDB 而不是 MySQL 的合适时机,为什么?

  • 组如何跟踪数据库架构更改?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目

    • 12 个回答
  • Marko Smith

    如何让sqlplus的输出出现在一行中?

    • 3 个回答
  • Marko Smith

    选择具有最大日期或最晚日期的日期

    • 3 个回答
  • Marko Smith

    如何列出 PostgreSQL 中的所有模式?

    • 4 个回答
  • Marko Smith

    列出指定表的所有列

    • 5 个回答
  • Marko Smith

    如何在不修改我自己的 tnsnames.ora 的情况下使用 sqlplus 连接到位于另一台主机上的 Oracle 数据库

    • 4 个回答
  • Marko Smith

    你如何mysqldump特定的表?

    • 4 个回答
  • Marko Smith

    使用 psql 列出数据库权限

    • 10 个回答
  • Marko Smith

    如何从 PostgreSQL 中的选择查询中将值插入表中?

    • 4 个回答
  • Marko Smith

    如何使用 psql 列出所有数据库和表?

    • 7 个回答
  • Martin Hope
    Jin 连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目 2014-12-02 02:54:58 +0800 CST
  • Martin Hope
    Stéphane 如何列出 PostgreSQL 中的所有模式? 2013-04-16 11:19:16 +0800 CST
  • Martin Hope
    Mike Walsh 为什么事务日志不断增长或空间不足? 2012-12-05 18:11:22 +0800 CST
  • Martin Hope
    Stephane Rolland 列出指定表的所有列 2012-08-14 04:44:44 +0800 CST
  • Martin Hope
    haxney MySQL 能否合理地对数十亿行执行查询? 2012-07-03 11:36:13 +0800 CST
  • Martin Hope
    qazwsx 如何监控大型 .sql 文件的导入进度? 2012-05-03 08:54:41 +0800 CST
  • Martin Hope
    markdorison 你如何mysqldump特定的表? 2011-12-17 12:39:37 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 对 SQL 查询进行计时? 2011-06-04 02:22:54 +0800 CST
  • Martin Hope
    Jonas 如何从 PostgreSQL 中的选择查询中将值插入表中? 2011-05-28 00:33:05 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 列出所有数据库和表? 2011-02-18 00:45:49 +0800 CST

热门标签

sql-server mysql postgresql sql-server-2014 sql-server-2016 oracle sql-server-2008 database-design query-performance sql-server-2017

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve