MySQL中可能遇到的问题及解决方法

一.在创建存储函数时,出现错误:
 ERROR 1418 (HY000): This function has none of DETERMINISTIC, NO SQL, or READS SQLDATA in its declaration binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable)
 解决方法: 1.mysql> SET GLOBAL log_bin_trust_function_creators = 1;
  2.在登录MySQL服务器是,加上 “--log-bin-trust-function-creators=1 ”参数并设置为1。
  3.一劳永逸的方法,在my.ini(my.cnf)中的[mysqld]区段中加上 log-bin-trust-function-creators=1。

   mysql> show variables like '%func%'; 
+---------------------------------+-------+
| Variable_name | Value |
+---------------------------------+-------+
| log_bin_trust_function_creators | OFF? |
+---------------------------------+-------+
1 row in set (0.00 sec)
mysql> set global log_bin_trust_function_creators=1;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like '%func%';
+---------------------------------+-------+
| Variable_name | Value |
+---------------------------------+-------+
| log_bin_trust_function_creators | ON? |
+---------------------------------+-------+
1 row in set (0.00 sec)

二.在声明变量时:mysql> declare my_sql int default 10;
 ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'declare my_sql int default 10' at line 1
 解决方法:变量的声明(DECLARE)必须发生在BEGIN-END语句块里,而且必须发生在同一个BEGIN-END语句块里的其他命令之前。下面是变量声明(DECLARE)的语法:
DECLARE varname1, varname2, varname3,… Datatype [DEFAULT value];

 注意:必须为所有的局部变量声明它们的数据类型。如果没有使用关键字 DEFAULT 进行设定(即初始化),局部变量的初始值都将是NULL

posted @ 2015-03-17 14:37  flay  阅读(518)  评论(0编辑  收藏  举报