MySQLѧϰ(1)Procedure,TRIGGER,FUNTCION
MySQLµÄÒ²Ö§³Ö´æ´¢¹ý³Ì£¬º¯Êý£¬´¥·¢Æ÷¡£
ÒÔϸ÷¸ö¹¦ÄܵÄÏêÊö£¬Ö÷ÒªÊÇʾÀý¡£
/**1.¶¨Òå·Ö¸î·û*/
DELIMITER //
/**2.´´½¨º¯Êý-¼ÆËãÁ½ÊýÖ®ºÍ*/
CREATE FUNCTION f_sum(num1 INT,num2 INT) RETURNS INT
BEGIN
RETURN num1+num2;
END;
//
/**
*3.´´½¨´æ´¢¹ý³Ì
*˼·£º3.1.Óиô洢¹ý³ÌÔòɾ³ý£¬3.2ÓÐʹÓõÄÖмä±íҲɾ³ý£¬²¢´´½¨¸Ã±í²åÈëÊý¾Ý£¬3.3ͳ¼Æ±íÖй²ÓжàÉÙÊý¾Ý²¢Í¨¹ýÊä³ö²ÎÊý·µ»Ø¸øµ÷ÓÃÕß 3.4ɾ³ýÖмäʹÓõ½µÄ±í
*/
DROP PROCEDURE IF EXISTS p_count ;//
DROP TABLE IF EXISTS T;//
CREATE TABLE T(i_num INT);//
INSERT INTO T VALUES(1),(2),(3);//
CREATE PROCEDURE p_count(OUT param INT)
BEGIN
SELECT COUNT(*) INTO param from T;
DROP TABLE T;
END;//
CALL p_count(@a);//
/**
*4.´´½¨´¥·¢Æ÷
*/
DROP TABLE IF EXISTS t;//
DROP TABLE IF EXISTS tx;//
CREATE TABLE tx(a INT);//
CREATE TABLE t(a INT);//
INSERT INTO t VALUES(2),(3),(4);//
CREATE TRIGGER tr_insert BEFORE INSERT ON t FOR EACH ROW
BEGIN
temp INT;
SELECT COUNT(*) INTO temp from t;
INSERT INTO tx VALUES(temp);
INSERT INTO tx SET a = NEW.a+1;
INSERT INTO tx VALUES(NEW.A+2);
END;
//
INSERT INTO t VALUES(1);
/**
*5.ʱ¼äÀàÐÍDATE,DATTIME,TIME,TIMESTAMP,YEAR
*²åÈëÊýֵʱ£º¿ÉÒÔÊÇ6£¬8£¬12£¬14λ£¬Î»Êý²»Í¬£¬MySQL²ÉÓõĸñʽ»¯·½Ê½Ò²²»Í¬¡£
*6-YYMMDD,8-YYYYMMDD,12-YYMMDDHHMMSS,14-YYYYMMDDHHMMSS
*²åÈë×Ö·û´®Ê±¸ù¾ÝÒÔÉÏ¿ÉÒÔÀàÍÆ,¾ßÌå¿ÉÒԲο¼MySQLµÄʹÓÃÊÖ²á
*/
DROP TABLE IF EXISTS t;//
CREATE TABLE t(ts TIMESTAMP);//
INSERT INTO t VALUES('09:02:01');//
INSERT INTO t VALUES(090101);
DROP TABLE IF EXISTS t£»//
CREATE TABLE 1P(a INT);
ÒÔÉÏËùÓж¼Í¨¹ý²âÊÔ¡£
MySQLµÄÁ½¸öº¯ÊýSELECT VERSION();--µÃµ½·þÎñÆ÷°æ±¾ÐÅÏ¢
SELECT CURRENT_DATE();--µÃµ½ÏµÍ³µ±Ç°ÈÕÆÚ£¬ÁíÍ⻹ÓÐCURRENT_TIMEµÃµ½µ±Ç°Ê±¼ä¡£
DELIMITER--·Ö¸ô·û£¬¶¨Ò幦ÄÜÓï¾ä½áÊøµÄ±êʶ,ĬÈÏΪ";"¡£
ÔÚд´æ´¢¹ý³ÌµÈ»áÉæ¼°µ½¶à¸ö";"£¬ÓÃËü×÷·Ö¸ô·ûÊDz»»á±àÒëͨ¹ýµÄ¡£
DELIMITER //£¬¶¨Òå"//"Ϊ·Ö¸ô·û£¬×÷ΪÕâ¸öÓï¾ä¿é¶ùµÄ½áÊø±êÖ¾¡£
CALL p£ßcount(@a);@aÔÚ¸ÃÁ¬½ÓÄÚÓÐЧ¡£
ÍØÕ¹£º½«£Í£ù£Ó£Ñ£Ì¿Í»§¶ËµÄËùÓÐÏÔʾÊý¾ÝÊä³öµ½Öƶ¨Îļþ£¬µÇ¼ºó mysql>tee D:/log/log.log
×¢ÒâÎļþµÄĿ¼һ¶¨Ò
Ïà¹ØÎĵµ£º
Mysql my.ini ÅäÖÃÎļþÏê½â
#BEGIN CONFIG INFO
#DESCR: 4GB RAM, ֻʹÓÃInnoDB, ACID, ÉÙÁ¿µÄÁ¬½Ó, ¶ÓÁиºÔØ´ó
#TYPE: SYSTEM
#END CONFIG INFO
#
# ´ËmysqlÅäÖÃÎļþÀý×ÓÕë¶Ô4GÄÚ´æ
# Ö÷ҪʹÓÃINNODB
#´¦Àí¸´ÔÓ¶ÓÁв¢ÇÒÁ¬½ÓÊýÁ¿½ÏÉÙµÄmysql·þÎñÆ÷
#
# ½«´ËÎļþ¸´ÖƵ½/etc/my.cnf ×÷Ϊȫ¾ÖÉèÖÃ,
# mysql-data-d ......
°²×°mysql
gem install mysql
ʹÓÃmysql£¬È磬rake db:migrate
»á±¨´í£º
E:\study\ruby\rails_space>rake db:migrate
(in E:/study/ruby/rails_space)
!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.
rake aborted!
193: ......
Query ProfilerÊÇMYSQL×Ô´øµÄÒ»ÖÖqueryÕï¶Ï·ÖÎö¹¤¾ß£¬Í¨¹ýËü¿ÉÒÔ·ÖÎö³öÒ»ÌõSQLÓï¾äµÄÐÔÄÜÆ¿¾±ÔÚʲôµØ·½¡£Í¨³£ÎÒÃÇÊÇʹÓõÄexplain,ÒÔ¼°slow query log¶¼ÎÞ·¨×öµ½¾«È··ÖÎö£¬µ«ÊÇQuery ProfilerÈ´¿ÉÒÔ¶¨Î»³öÒ»ÌõSQLÓï¾äÖ´Ðеĸ÷ÖÖ×ÊÔ´ÏûºÄÇé¿ö£¬±ÈÈçCPU£¬IOµÈ£¬ÒÔ¼°¸ÃSQLÖ´ÐÐËùºÄ·ÑµÄʱ¼äµÈ¡£²»¹ý¸Ã¹¤¾ßÖ»ÓÐÔÚMYSQL 5.0.37ÒÔ ......
MySQL ODBC connection strings
Open connection to local MySQL database using MySQL ODBC 3.51 Driver
"Provider=MSDASQL; DRIVER={MySQL ODBC 3.51Driver}; SERVER= localhost; DATABASE=Your_MySQL_Database; UID= Your_Username; PASSWORD=Your_Password; OPTION=3"
MySQL OLE DB & OleDbConnection (.NET fr ......
select * for updateËø±íµÄÎÊÌâ
ÓÉÓÚInnoDBÔ¤ÉèÊÇRow-Level Lock£¬ËùÒÔÖ»ÓС¸Ã÷È·¡¹µÄÖ¸¶¨Ö÷¼ü£¬MySQL²Å»áÖ´ÐÐRow lock (Ö»Ëøס±»Ñ¡È¡µÄ×ÊÁÏÀý) £¬·ñÔòMySQL½«»áÖ´ÐÐTable Lock (½«Õû¸ö×ÊÁÏ±íµ¥¸øËøס)¡£
¾Ù¸öÀý×Ó:
¼ÙÉèÓиö±íµ¥products £¬ÀïÃæÓÐid¸úname¶þ¸öÀ¸Î»£¬idÊÇÖ÷¼ü¡£
Àý1: (Ã÷È·Ö¸¶¨Ö÷¼ü£¬²¢ÇÒÓд˱Ê×ÊÁÏ£¬ ......