mysqlÖÐcountº¯Êý×¢ÒâÊÂÏî
񡜧
CREATE TABLE `user` (
`id` int(5) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(10) DEFAULT NULL,
`password` varchar(10) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=latin1
ÆäÖÐÓÐÊý¾ÝΪ£º
1 name1 123456
2 name2 123456
3 name3 123456
4 name4 NULL
ÒÔÏÂÈý¸ö²éѯ·µ»Ø¼¸ÄØ£¿
£¨1£©select count(*) from `user`
£¨2£©select count(name) from `user`
£¨3£©select count(password) from `user`
´ð°¸ÊÇ£º4,4,3
ÒòΪ£º
£¨1£©count(*)ÊǶÔÐÐÊýÄ¿½øÐмÆÊý£¬ËùÒÔµ±È»ÊÇ4
£¨2£©count(column_name)ÊǶÔÁÐÖв»Îª¿ÕµÄÐнøÐмÆÊý£¬ËùÒÔcount(name)=4£¬¶øcount(password)=3
Ïà¹ØÎĵµ£º
create database sample;
create table 't_user' (
'id' int(11) not null auto_increment,
'name' varchar(100) not null default '',
primary key ('id')
) type=myisam;
Ñ¡ÏîÖ»ÔÚMySQL 3.23ºÍÒÔºó°æ±¾Öб»ÊµÏÖ¡£
²»Í¬µÄ±íÀàÐÍÊÇ£º
ISAM ÔÀ´µÄ±í´¦ÀíÆ ......
ÎÒµÄϵͳÊÇubuntu6.06£¬×î½üÐÂ×°ºÃµÄmysqlÔÚ½øÈëmysql¹¤¾ßʱ£¬×ÜÊÇÓдíÎóÌáʾ:
# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
ʹÓÃÍøÉϽéÉܵķ½·¨ÐÞ¸ÄrootÓû§µÄÃÜÂ룺
# mysqladmin -uroot -p password 'newpassword'
Enter pass ......
Ò»¡¢CREATE TABLE ·½·¨
Õû±í¸´ÖÆ # create table бí select * from ¾É±í;
½á¹¹¸´ÖÆ # create table бí select * from ¾É±í where 1<>1;
¶þ¡¢INSERT INTO ·½·¨
µÃµ½½¨±íÓï¾ä # show create table ¾É±í;
н¨±í
¸´ÖÆÊý¾Ýµ½Ð±í INSERT INTO new_table(col1,col2,...) (SELECT col1,col2,... from old_table); ......
¶ÔmysqlµÄÓÅ»¯²»ÔÚÐУ¬¸ã¹ý¼¸´ÎÓÅ»¯£¬µ«ÊǶ¼²»ÊǺÜÀíÏ룬»¹ÊÇÀË·Ñ×ÊÔ´Ì«¶à¡£Ò»Ö±·¢ÏÖÎÒµÄmysqlµÄ»º´æÃüÖÐÂʼ«²î£¬Çé¿öÁ¼ºÃµÄʱºòµ½´ï¹ý60-70%£¬µ«ÊÇÔËÐÐʱ¼äÒ»³¤£¬Ö»ÓÐ10-20%¡£²éÁËһЩ×ÊÁÏ£¬¹ØÓÚ»º´æµÄһЩ²ÎÊý¼Ç¼
mysql> SHOW VARIABLES LIKE ‘%query_cache%’;
+—————&m ......
ÔÀí
QueryCache(ÏÂÃæ¼ò³ÆQC)ÊǸù¾ÝSQLÓï¾äÀ´cacheµÄ¡£Ò»¸öSQL²éѯÈç¹ûÒÔselect¿ªÍ·£¬ÄÇôMySQL·þÎñÆ÷½«³¢ÊÔ¶ÔÆäʹÓÃ
QC¡£Ã¿¸öCache¶¼ÊÇÒÔSQLÎı¾×÷ΪkeyÀ´´æµÄ¡£ÔÚÓ¦ÓÃQC֮ǰ£¬SQLÎı¾²»»á±»×÷Èκδ¦Àí¡£Ò²¾ÍÊÇ˵£¬Á½¸öSQLÓï¾ä£¬Ö»ÒªÏà²îÄÄÅÂÊÇÒ»¸ö×Ö·û£¨ÀýÈç´óСд²»Ò»Ñù£»¶àÒ»¸ö¿Õ¸ñµÈ£©£¬ÄÇôÕâÁ½¸öSQL½«Ê¹Óò»Í¬µÄÒ» ......