MySql ´æ´¢¹ý³Ì
MySQL ´æ´¢¹ý³ÌÊÇ´Ó MySQL 5.0 ¿ªÊ¼Ôö¼ÓµÄй¦ÄÜ¡£´æ´¢¹ý³ÌµÄÓŵãÓÐÒ»Âá¿ð¡£²»¹ý×îÖ÷ÒªµÄ»¹ÊÇÖ´ÐÐЧÂʺÍSQL ´úÂë·â×°¡£ÌرðÊÇ SQL ´úÂë·â×°¹¦ÄÜ£¬Èç¹ûûÓд洢¹ý³Ì£¬ÔÚÍⲿ³ÌÐò·ÃÎÊÊý¾Ý¿âʱ£¨ÀýÈç PHP£©£¬Òª×éÖ¯ºÜ¶à SQL Óï¾ä¡£ÌرðÊÇÒµÎñÂß¼¸´ÔÓµÄʱºò£¬Ò»´ó¶ÑµÄ SQL ºÍÌõ¼þ¼ÐÔÓÔÚ PHP ´úÂëÖУ¬ÈÃÈ˲»º®¶øÀõ¡£ÏÖÔÚÓÐÁË MySQL ´æ´¢¹ý³Ì£¬ÒµÎñÂß¼¿ÉÒÔ·â×°´æ´¢¹ý³ÌÖУ¬ÕâÑù²»½öÈÝÒ×ά»¤£¬¶øÇÒÖ´ÐÐЧÂÊÒ²¸ß¡£
Ò»¡¢MySQL ´´½¨´æ´¢¹ý³Ì
“pr_add” ÊǸö¼òµ¥µÄ MySQL ´æ´¢¹ý³Ì£¬Õâ¸ö´æ´¢¹ý³ÌÓÐÁ½¸ö int ÀàÐ͵ÄÊäÈë²ÎÊý “a”¡¢“b”£¬·µ»ØÕâÁ½¸ö²ÎÊýµÄºÍ¡£
drop procedure if exists pr_add;
-- ¼ÆËãÁ½¸öÊýÖ®ºÍ
create procedure pr_add
(
a int,
b int
)
begin
declare c int;
if a is null then
set a = 0;
end if;
if b is null then
set b = 0;
end if;
set c = a + b;
select c as sum;
/*
return c;- ²»ÄÜÔÚ MySQL ´æ´¢¹ý³ÌÖÐʹÓá£return Ö»ÄܳöÏÖÔÚº¯ÊýÖС£
/
end;
¶þ¡¢µ÷Óà MySQL ´æ´¢¹ý³Ì
call pr_add(10, 20);
Ö´ÐÐ MySQL ´æ´¢¹ý³Ì£¬´æ´¢¹ý³Ì²ÎÊýΪ MySQL Óû§±äÁ¿¡£
set @a = 10;
set @b = 20;
call pr_add(@a, @b);
Èý¡¢MySQL ´æ´¢¹ý³ÌÌصã
´´½¨ MySQL ´æ´¢¹ý³ÌµÄ¼òµ¥Ó﷨Ϊ£º
create procedure ´æ´¢¹ý³ÌÃû×Ö()
(
[in|out|inout] ²ÎÊý datatype
)
begin
MySQL Óï¾ä;
end;
MySQL ´æ´¢¹ý³Ì²ÎÊýÈç¹û²»ÏÔʽָ¶¨“in”¡¢“out”¡¢“inout”£¬ÔòĬÈÏΪ“in”¡£Ï°¹ßÉÏ£¬¶ÔÓÚÊÇ“in” µÄ²ÎÊý£¬ÎÒÃǶ¼²»»áÏÔʽָ¶¨¡£
1. MySQL ´æ´¢¹ý³ÌÃû×ÖºóÃæµÄ“()”ÊDZØÐëµÄ£¬¼´Ê¹Ã»ÓÐÒ»¸ö²ÎÊý£¬Ò²ÐèÒª“()”
2. MySQL ´æ´¢¹ý³Ì²ÎÊý£¬²»ÄÜÔÚ²ÎÊýÃû³ÆÇ°¼Ó“@”£¬È磺“@a int”¡£ÏÂÃæµÄ´´½¨´æ´¢¹ý³ÌÓï·¨ÔÚ MySQL ÖÐÊÇ´íÎóµÄ£¨ÔÚ SQL Server ÖÐÊÇÕýÈ·µÄ£©¡£ MySQL ´æ´¢¹ý³ÌÖеıäÁ¿£¬²»ÐèÒªÔÚ±äÁ¿Ãû×ÖÇ°¼Ó“@”£¬ËäÈ» MySQL ¿Í»§¶ËÓû§±äÁ¿Òª¼Ó¸ö“@”¡£
create procedure pr_add
(
@a int,
Ïà¹ØÎĵµ£º
ÔÎÄÁ´½Ó£ºhttp://hi.baidu.com/171892549/blog/item/14818d0ac616ee34b1351dbd.html
ÔÚÊý¾Ý¿â±íÖУ¬Ê¹ÓÃË÷Òý¿ÉÒÔ´ó´óÌá¸ß²éѯËٶȡ£
¼ÙÈçÎÒÃÇ´´½¨ÁËÒ»¸ö testIndex ±í£º
CREATE TABLE testIndex(i_testID INT NOT NULL,vc_Name VARCHAR(16) NOT NULL);
ÎÒÃÇËæ»úÏòÀïÃæ²åÈëÁË 1000 Ìõ¼Ç¼£¬ÆäÖÐÓÐÒ»Ìõ i_testID vc_Name ......
ÎÒÒ»Ö±ÊÇʹÓÃmysqlÕâ¸öÊý¾Ý¿âÈí¼þ£¬Ëü¹¤×÷±È½ÏÎȶ¨£¬Ð§ÂÊÒ²ºÜ¸ß¡£ÔÚÓöµ½ÑÏÖØÐÔÄÜÎÊÌâʱ£¬Ò»°ã¶¼ÓÐÕâô¼¸ÖÖ¿ÉÄÜ£º
1¡¢Ë÷ÒýûÓн¨ºÃ£»
2¡¢sqlд·¨¹ýÓÚ¸´ÔÓ£»
3¡¢ÅäÖôíÎó£»
4¡¢»úÆ÷ʵÔÚ¸ººÉ²»ÁË£»
1¡¢Ë÷ÒýûÓн¨ºÃ
Èç¹û¿´µ½mysqlÏûºÄµÄcpuºÜ´ó£¬¿ÉÒÔÓÃmysqlµÄclient¹¤¾ßÀ´¼ì²é¡£
ÔÚlinuxÏÂÖ´ÐÐ
/usr/local/mysql/bin/ ......
½¨Á¢Íâ¼üµÄÇ°Ì᣺ ±¾±íµÄÁбØÐëÓëÍâ¼üÀàÐÍÏàͬ(Íâ¼ü±ØÐëÊÇÍâ±íÖ÷¼ü)¡£
Íâ¼ü×÷Ó㺠ʹÁ½ÕűíÐγɹØÁª£¬Íâ¼üÖ»ÄÜÒýÓÃÍâ±íÖеÄÁеÄÖµ£¡
Ö¸¶¨Ö÷¼ü¹Ø¼ü×Ö£º foreign key(ÁÐÃû)
ÒýÓÃÍâ¼ü¹Ø¼ü×Ö£º references <Íâ¼ü±íÃû>(Íâ¼üÁÐÃû)
ʼþ´¥·¢ÏÞÖÆ: on deleteºÍon update , ¿ÉÉè²ÎÊýcascade(¸úËæÍâ¼ü¸Ä¶¯ ......
¶ÔÓÚÿ¸öÀàÐÍÓµÓеÄÖµ·¶Î§ÒÔ¼°²¢ÇÒÖ¸¶¨ÈÕÆÚºÎʱ¼äÖµµÄÓÐЧ¸ñʽµÄÃèÊö¼û7.3.6 ÈÕÆÚºÍʱ¼äÀàÐÍ¡£
ÕâÀïÊÇÒ»¸öʹÓÃÈÕÆÚº¯ÊýµÄÀý×Ó¡£ÏÂÃæµÄ²éѯѡÔñÁËËùÓмǼ£¬Æädate_colµÄÖµÊÇÔÚ×îºó30ÌìÒÔÄÚ£º
mysql> SELECT something from table
WHERE TO_DAYS(NOW()) - TO_DAYS(date_col) <= 30;
DAYOFWEEK(date)
·µ»ØÈÕÆ ......
Æô¶¯£ºnet start mySql;
½øÈ룺mysql -u root -p/mysql -h localhost -u root -p databaseName;
ÁгöÊý¾Ý¿â£ºshow databases;
Ñ¡ÔñÊý¾Ý¿â£ºuse databaseName;
Áгö±í¸ñ£ºshow tables£»
ÏÔʾ±í¸ñÁеÄÊôÐÔ£ºshow columns from tableName£»
½¨Á¢Êý¾Ý¿â£ºsource fileNam ......