mysqlÖÐʱ¼ä²éѯº¯Êý£¨°üÀ¨Ê±¼ä´Á£©
ÕâЩº¯Êý¶¼ÊÇMySQL×Ô´øµÄ£¬¿ÉÒÔÖ±½ÓʹÓÃÔÚPHPдµÄMySQL²éѯÓï¾äÖÐŶ
1-CURDATE()»òCURRENT_DATE()ºÍCURTIME()»òCURRENT_TIME()
ÕâÁ½¸öº¯ÊýÊDZȽϳ£Óõ½µÄ£¬¹ËÃû˼Ò壬µÚÒ»¸ö·µ»Øµ±Ç°ÈÕÆÚ£¬µÚ¶þ¸ö·µ»Øµ±Ç°Ê±¼ä
¿ÉÒÔÔÚMySQL¿Í»§¶Ë»òÕßPHPÓï¾äÀïд"SELECT CURDATE(),CURTIME()"²é¿´Ïà¹ØÐÅÏ¢.
»¹ÓÐÒ»¸öºÜÖØÒªµÄº¯ÊýNOW()£¬·µ»Øµ±Ç°ÈÕÆÚºÍʱ¼äÆäʵ¾ÍÊÇÉÏÃæÁ½¸öº¯Êý·µ»Ø½á¹ûµÄºÏ²¢¡£
2-DATE_ADDºÍDATE_SUB(date,INTERVAL int keyword)
ÕâÁ½¸öº¯ÊýºÜÖØÒª£¬·µ»ØÈÕÆÚdate¼ÓÉÏ»ò¼õÈ¥¸ñʽ»¯µÄʱ¼äINTERVAL int£¬Ïñ½ñÌìÓиöÅóÓÑÌáµ½ÈçºÎ²éѯһÖÜÖ®ÄÚµÄÊý¾Ý¾ÍÒªÓõ½Õâ¸öº¯Êý¡£
ÏÂÃæ½²Ò»ÏÂINTERVAL int keyword
ÏȾٸöÀý×Ó
PHP ´úÂë:
SELECT
*
from tblname WHERE TIME
>
DATE_SUB
(
NOW
(),
INTERVAL 1 MONTH
)
Õâ¸öÓï¾äÖ´Ðк󷵻رíÖÐËùÓÐTIME×Ö¶ÎÖµ´Óµ±Ç°ÈÕÆÚÆðÒ»¸öÔÂÖ®ÄÚµÄÊý¾Ý
PHP ´úÂë:
SELECT
*
from tblname WHERE TIME
>
DATE_SUB
(
NOW
(),
INTERVAL
"1-1"
YEAR_MONTH
)
Õâ¸öÓï¾ä·µ»Ø¾à½ñÒ»ÄêÁãÒ»¸öÔÂÖ®ÄÚµÄÊý¾Ý
Èç¹ûÓõ½DAY_SECOND²ÎÊý£¬Ç°ÃæµÄint¾Í±ØÐëÈç "1 12:23:34"ÕâÑùµÄ¸ñʽ
ÏÂÃæÊÇkeyword²ÎÊýÁбí
PHP ´úÂë:
MICROSECOND
SECOND
MINUTE
HOUR
DAY
WEEK
MONTH
QUARTER
YEAR
SECOND_MICROSECOND
MINUTE_MICROSECOND
MINUTE_SECOND
HOUR_MICROSECOND
HOUR_SECOND
HOUR_MINUTE
DAY_MICROSECOND
DAY_SECOND
DAY_MINUTE
DAY_HOUR
YEAR_MONTH
ÆäÖÐQUARTERºÍWEEKÊÇMySQL5Ö®ºó²ÅÓеġ£
EXTRACT(keyword from date)-Õâ¸öº¯Êý´ÓÌṩµÄÈÕÆÚÖÐժȡ³öÏà¹ØÐÅÏ¢
PHP ´úÂë:
SELECT EXTRACT
(
DAY from NOW
())
¾Í·µ»Øµ±Ç°ÈÕÆÚµÄDAY£¬½ñÌìÊÇ16Èվͷµ»ØÊý×Ö16¡£
ÏÂÃæ½éÉܼ¸¸öÈÕÆÚʱ¼äº¯Êý
DAYOFWEEK(NOW())·µ»Øµ±Ç°ÈÕÆÚÊÇÕâÖܵĵÚÒ»Ì죬ÖÜÈÕÊǵÚÒ»Ì죬
DAYNAME(NOW())·µ»ØÐÇÆÚµÄÃû×Ö
DAYOFMONTH(NOW()) ·µ»Ø½ñÌìÊǼ¸ºÅ
DAYOFYEAR(NOW()) ·µ»Ø½ñÌìÊǽñÄêµÄµÚ¶àÉÙÌì
YEAR(NOW()) WEEK(NO
Ïà¹ØÎĵµ£º
¶ÔÓÚÈκÎÒ»¸öÊý¾Ý¿â¹ÜÀíϵͳÀ´Ëµ£¬ÄÚ´æµÄ·ÖÅäʹÓþø¶Ô¿ÉÒÔËãµÄÉÏÊÇÆäºËÐÄÖ®Ò»ÁË£¬ËùÒԺܶàÏ£Íû¸üΪÉîÈëÁ˽âijÊý¾Ý¿â¹ÜÀíϵͳµÄÈË£¬¶¼»áÏ£ÍûÒ»¿ú¾¿¾¹£¬ÎÒÒ²²»ÀýÍâ¡£
´ÓÄÚ´æµÄʹÓ÷½Ê½MySQL Êý¾Ý¿âµÄÄÚ´æʹÓÃÖ÷Òª·ÖΪÒÔÏÂÁ½Àà
* Ï̶߳ÀÏíÄÚ´æ
* È«¾Ö¹²ÏíÄÚ´æ
½ñÌìÕâƪÎÄÕÂÔÝʱÏÈ·ÖÎö MySQL ÖÐÖ÷ÒªµÄ “Ï̶߳ÀÏíÄ ......
±¾ÎĽéÉÜÁËÊý¾Ý¿âË÷Òý£¬¼°ÆäÓÅ¡¢È±µã¡£Õë¶ÔMySQLË÷ÒýµÄÌص㡢ӦÓýøÐÐÁËÏêϸµÄÃèÊö¡£·ÖÎöÁËÈçºÎ±ÜÃâMySQLÎÞ·¨Ê¹Óã¬ÈçºÎʹÓÃEXPLAIN·ÖÎö²éѯÓï¾ä£¬ÈçºÎÓÅ»¯MySQLË÷ÒýµÄÓ¦Óᣱ¾ÎÄÕª×Ô¡¶MySQL 5ȨÍþÖ¸ÄÏ¡·(3rd)µÄ8.9½Ú¡£(2007.07.05×îºó¸üÐÂ)
Ë÷ÒýÊÇÒ»ÖÖÌØÊâµÄÎļþ(InnoDBÊý¾Ý±íÉϵÄË÷ÒýÊDZí¿Õ¼äµÄÒ»¸ö× ......
1.µÇ¼£º mysql -uroot -p
2.LinuxÏÂmysql ²»ÄÜÍâÍø·ÃÎÊ
ÒѾÔÚMYSQLÀïgrantÁËȨÏÞÁË¡£ÔÚÍâÍø»¹ÊDz»ÄÜ·ÃÎÊ .
ÎÊÌ⣺
cat /etc/mysql/my.conf
ÕÒµ½ÏÂÃæÒ»ÐÐ
bind-address = 127.0.0.1
Î ......
MySQL Ìí¼ÓÍâ¼ü
DROP TABLE IF EXISTS `nation`;
CREATE TABLE `nation`(
`pii_Nation` smallint(2) unsigned NOT NULL default '0',
`pii_NatinoName` varchar(40) NOT NULL default '',
PRIMARY KEY (`pii_Nation`)
)ENGINE=InnoDB DEFAULT CHARSE ......
½ñÌì¸øÐÂÀ´µÄÔ±¹¤Á¬½ÓÊý¾Ý¿â£¬ÐÞ¸ÄÁËÒ»ÏÂmysql rootÓû§µÄÃÜÂ룬ÎÒÏÂÔصÄÊÇ´ò°üµÄredMine£¬Ä¬ÈÏÃÜÂëÊÇ¿Õ£¬ÐÞ¸ÄÃÜÂëÖ®ºóÖØÆôredmine£¬phpAdmin Á´½Ó²»ÉÏmysqlÊý¾Ý¿âÁË£¬ÎÒÒ²ÐÞ¸ÄÁËphpadminÎļþ¼ÐϵÄconfig.inc.phpµÄÃÜÂ룬»¹ÊDz»ÐУ¬Ìáʾ#1130 - Host 'localhost' is not allowed to connect to this MySQL server´íÎó£¬Ã÷ ......