MySql控制台没有响应

时间:2012-07-29 10:51:31

标签: mysql sql triggers console delimiter

输入触发器后,控制台似乎处于奇怪状态,其中没有响应正常命令。我是无意中用分隔符做的吗?

mysql> use nntp;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+---------------------+
| Tables_in_nntp      |
+---------------------+
| articles            |
| newsgroups          |
| newsgroups_articles |
+---------------------+
3 rows in set (0.00 sec)

mysql> show triggers;
Empty set (0.00 sec)

mysql> DELIMITER $$
mysql> USE `nntp`$$
Database changed
mysql> CREATE
    -> TRIGGER `nntp.newsgroups.before_insert`
    -> BEFORE INSERT ON `nntp`.`newsgroups`
    -> FOR EACH ROW
    -> BEGIN
    -> set new.hash = md5(new.newsgroup);
    -> END$$
Query OK, 0 rows affected (0.18 sec)

mysql> DELIMITER $$
mysql> USE `nntp`$$
Database changed
mysql> CREATE
    -> TRIGGER `nntp.newsgroups.before_update`
    -> BEFORE UPDATE ON `nntp`.`newsgroups`
    -> FOR EACH ROW
    -> BEGIN
    -> set new.hash = md5(new.newsgroup);
    -> END$$
Query OK, 0 rows affected (0.19 sec)

mysql> show triggers;
    -> ^CCtrl-C -- exit!
Aborted
thufir@dur:~$ 

1 个答案:

答案 0 :(得分:1)

您需要在创建触发器或例程时更改分隔符,否则您将不得不为随后的所有语句使用相同的分隔符(在本例中为$$)。

例如:

mysql> DELIMITER $$
mysql> USE `nntp`$$
Database changed
mysql> CREATE
    -> TRIGGER `nntp.newsgroups.before_update`
    -> BEFORE UPDATE ON `nntp`.`newsgroups`
    -> FOR EACH ROW
    -> BEGIN
    -> set new.hash = md5(new.newsgroup);
    -> END$$
Query OK, 0 rows affected (0.19 sec)

mysql> DELIMITER ;
mysql> show triggers;

请注意第二次使用DELIMITER关键字。