› MySQL 5.5 Community Server
› MySQL 5.6 Community Server
› Percona Configuration Wizard
› XtraBackup 搭建主从复制
Great Sites on MySQL
› Percona
› MySQL Performance Blog
› Severalnines
推荐管理工具
› Sequel Pro
› phpMyAdmin
推荐书目
› MySQL Cookbook
MySQL 相关项目
› MariaDB
› Drizzle
参考文档
› http://mysql-python.sourceforge.net/MySQLdb.html
micookie
V2EX  ›  MySQL

mysql 触发器定义变量一直报错。

  •  
  •   micookie · Aug 3, 2017 · 4305 views
    This topic created in 3360 days ago, the information mentioned may be changed or developed.
    • 前言:虽然一直在用数据库,但是一直没有涉及到触发器这块,最近有个需求要改,修改代码不是很方便,就想通过触发器去实现这个功能,也很方便,然后就学习了一下 mysql 的触发器,然后就发现很多问题,网上的代码都不能正常的运行。

    • 问题:遇到的问题是不能正确的在 mysql 触发器中定义变量,网上找到的很多方法都不能正常的创建,DECLARE,@set 等方法。

    • 下面的例子:下面的 demo 是,声明了一个 m_id 的变量,然后赋值了 aaa,然后作为一个插入的数据,但是创建的过程中会出现错误。

    
    CREATE  TRIGGER `增加数据自动插入 log` AFTER INSERT ON `qw_links`
    FOR EACH ROW 
    
    DECLARE m_id varchar(255);
    
    set m_var = 'aaa';
    
    INSERT INTO  `qw_log` (`name` ,`t` ,`ip` ,`log`)VALUES ('添加 links', NOW() ,  m_var ,"123");
    
    
    • 有了解的麻烦帮忙看下,谢谢~
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   5807 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 51ms · UTC 02:03 · PVG 10:03 · LAX 19:03 · JFK 22:03
    ♥ Do have faith in what you're doing.