MySQL ´æ´¢¹ý³Ì
£ÛתÔØ£ÝMySQL£ºMySQL ´´½¨´æ´¢¹ý³Ì£¨MySQL 5.0£©
2008-09-11 22:14
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 ¿Í»§¶ËÓû§±äÁ¿Òª¼Ó¸ö&
Ïà¹ØÎĵµ£º
Scale Out£ººáÏòÀ©Õ¹£¬Ôö¼Ó´¦Àí½ÚµãÌá¸ßÕûÌå´¦ÀíÄÜÁ¦
Scale Up£º×ÝÏòÀ©Õ¹£¬Í¨¹ýÌáÉýµ¥¸ö½ÚµãµÄ´¦ÀíÄÜÁ¦´ïµ½ÌáÉýÕûÌå´¦ÀíÄÜÁ¦µÄÄ¿µÄ
Replication
MySQLµÄreplicationÊÇÒì²½µÄ£¬ÊÊÓÃÓÚ¶ÔÊý¾ÝʵʱÐÔÒªÇó²»ÊÇÌرð¹Ø¼üµÄ³¡¾°¡£slave¶ËµÄIOÏ̸߳ºÔð´Ómaster¶ÁÈ¡ÈÕÖ¾£¬SQLÏß ³ÌרߺÔðÔÚslave¶ËÓ¦ÓôÓmaster¶Á¹ýÀ´µÄÈÕÖ¾£¨ÔçÆÚ ......
×öÊý¾Ý¿âµ÷ÓÅ£¬Ò»¸ö¼òµ¥µÄtip¾ÍʹÐÔÄÜÌáÉýÒ»´ó¿éʱ£¬±»°ïÖúµÄÈË×ÔÈ»ÊǸßÐ˶øÇҸм¤£¬ÎÒÒ²ÊÇÂúÐÄ»¶Ï²¡£ÓÃËùѧ°ïÖúÁËËûÈË£¬Ò²ËµÃ÷»¹ÊÇÓÐÒ»¼¼Ö®³¤µÄ£¬ÓÐÒ»ÃÅÄܹ»Ñø»î×Ô¼ºµÄÊÖÒÕ¡£Ò²ËãÊÇÊÖÒÕÈË°¡¡£
ͬÊÂÈÃÎÒ°ïÖúÓÅ»¯£¬ÔÚslow query logÀï·¢ÏÖÓÐÁ½¸öSQLÖ´ÐеĴÎÊý×î¶à£¬²¢ÇÒÿ´Î¶¼ÔÚÁ½ÃëÒÔÉÏ¡£ÓÃexplain¿´ÁË£¬Ò²Î´·¢ÏÖË÷ÒýʹÓ÷ ......
Unix&Linux£º
1.ÓÃroot»òÕßÔËÐÐmysqldµÄÓû§µÇ¼ϵͳ£»
2£®ÀûÓÃkillÃüÁî½áÊøµômysqldµÄ½ø³Ì£»
3£®Ê¹ÓÃ--skip-grant-tables²ÎÊýÆô¶¯MySQL Server
shell>mysqld_safe --skip-grant-tables &
4.Ϊroot@localhostÉèÖÃÐÂÃÜÂë
shell>mysqladmin -u root flush-privileges password "newpassword" ......
Ò». Æô¶¯²ÎÊýÓÅ»¯
ÐÞ¸Ä my.cnf (»òÕßmy.ini)£¬¼ÓÈë/ÐÞ¸ÄÒÔϼ¸ÐÐ
#É趨»º´æµÄÁ¬½ÓÊý,½ÚÊ¡Á¬½ÓʱµÄ¿ªÏú
back_log = 64
#½ûÓÃÎļþϵͳÍⲿËø
external-locking = 0
#½ûÓÃBDB,Èç¹ûÄãȷʵ²»ÐèÒªµÄ»°,innodbÒ²ÊÇÈç´Ë
skip-bdb
#Ë÷Òý»º³å,Èç¹ûÊÇרÓõÄÊý¾Ý¿â·þÎñÆ÷,¿ÉÒÔÉèÖøߴï·þÎñÆ÷ÄÚ´æµÄÒ»°ë,Èç¹û²»ÊÇרÓõÄ,
#»¹ÊÇÉ ......
InnoDBÊÇmysqlÊý¾Ý¿âÖÐΨһһ¸öÖ§³ÖÍâ¼üµÄÒýÇ棬µ«ÊDzîÖµµÄʱºòÈ´µÃ×¢ÒâÒ»ÏÂ
±ÈÈçÓÐÁ½ÕÅ±í£¬album(id,name,path) £¬picture(id,name,path,parent_album)£¬ÆäÖбí2ÖÐparent_albumÊÇÍâ¼ü
´Ëʱ²îÖµinsert into picture (name,path,parent_album) values ("pic","path",68) (68ÊÇÒ»¸öÏà²áµÄid)
mysql»á±¨´í"Failed to read a ......