MySQL²åÈë¶àÌõ¼Ç¼ºÍREPLACEÓï¾ä
1.ʹÓÃINSERT²åÈë¶àÌõ¼Ç¼
¿´µ½Õâ¸ö±êÌâÒ²Ðí´ó¼Ò»áÎÊ£¬ÕâÓÐʲôºÃ˵µÄ£¬µ÷Óöà´ÎINSERTÓï¾ä²»¾Í¿ÉÒÔ²åÈë¶àÌõ¼Ç¼ÁËÂð!µ«Ê¹ÓÃÕâÖÖ·½·¨ÒªÔö¼Ó·þÎñÆ÷µÄ¸ººÉ£¬ÒòΪ£¬
Ö´ÐÐÿһ´ÎSQL·þÎñÆ÷¶¼ÒªÍ¬Ñù¶ÔSQL½øÐзÖÎö¡¢ÓÅ»¯µÈ²Ù×÷¡£ÐÒºÃMySQLÌṩÁËÁíÒ»ÖÖ½â¾ö·½°¸£¬¾ÍÊÇʹÓÃÒ»ÌõINSERTÓï¾äÀ´²åÈë¶àÌõ¼Ç¼¡£Õâ²¢
²»ÊDZê×¼µÄSQLÓï·¨£¬Òò´ËÖ»ÄÜÔÚMySQLÖÐʹÓá£
INSERT INTO users(name, age) VALUES('Ò¦Ã÷', 25), ('±È¶û.¸Ç´Ä', 50),
('»ðÐÇÈË', 600);
ÉÏÃæµÄINSERT
Óï¾äÏòusers±íÖÐÁ¬Ðø²åÈëÁË3Ìõ¼Ç¼¡£ÖµµÃ×¢ÒâµÄÊÇ£¬ÉÏÃæµÄINSERTÓï¾äÖеÄVALUESºó±ØÐëÿһÌõ¼Ç¼µÄÖµ·Åµ½Ò»¶Ô(…)ÖУ¬ÖмäʹÓÃ","
·Ö¸î¡£¼ÙÉèÓÐÒ»¸ö±ítable1
CREATE TABLE table1(n INT);
Èç¹ûÒªÏòtable1ÖвåÈë5Ìõ¼Ç¼£¬ÏÂÃæÐ´·¨ÊÇ´íÎóµÄ£º
INSERT INTO table1 (i) VALUES(1,2,3,4,5);
MySQL½«»áÅ׳öÏÂÃæµÄ´íÎó
ERROR 1136: Column count doesn't match value count at row 1
¶øÕýÈ·µÄд·¨Ó¦¸ÃÊÇÕâÑù£º
INSERT INTO table1(i) VALUES(1),(2),(3),(4),(5);
µ±È»£¬ÕâÖÖд·¨Ò²¿ÉÒÔÊ¡ÂÔÁÐÃû£¬ÕâÑùÿһ¶ÔÀ¨ºÅÀïµÄÖµµÄÊýÄ¿±ØÐëÒ»Ö£¬¶øÇÒÕâ¸öÊýÄ¿±ØÐëºÍÁÐÊýÒ»Ö¡£È磺
INSERT INTO table1 VALUES(1),(2),(3),(4),(5);
2. REPLACEÓï¾ä
ÎÒÃÇÔÚʹÓÃÊý¾Ý¿âʱ¿ÉÄܻᾳ£Óöµ½ÕâÖÖÇé¿ö¡£Èç¹ûÒ»¸ö±íÔÚÒ»¸ö×Ö¶ÎÉϽ¨Á¢ÁËΨһË÷Òý£¬µ±ÎÒÃÇÔÙÏòÕâ¸ö±íÖÐʹÓÃÒѾ´æÔڵļüÖµ²åÈëÒ»Ìõ¼Ç¼£¬ÄÇ
½«»áÅ׳öÒ»¸öÖ÷¼ü³åÍ»µÄ´íÎó¡£µ±È»£¬ÎÒÃÇ¿ÉÄÜÏëÓÃмǼµÄÖµÀ´¸²¸ÇÔÀ´µÄ¼Ç¼ֵ¡£Èç¹ûʹÓô«Í³µÄ×ö·¨£¬±ØÐëÏÈʹÓÃ
DELETEÓï¾äɾ³ýÔÏȵļǼ£¬È»ºóÔÙʹÓÃINSERT²åÈëеļǼ¡£¶øÔÚMySQLÖÐΪÎÒÃÇÌṩÁËÒ»ÖÖеĽâ¾ö·½°¸£¬Õâ¾ÍÊÇREPLACEÓï¾ä¡£Ê¹ÓÃ
REPLACE²åÈëÒ»Ìõ¼Ç¼ʱ£¬Èç¹û²»Öظ´£¬REPLACE¾ÍºÍINSERTµÄ¹¦ÄÜÒ»Ñù£¬Èç¹ûÓÐÖØ¸´¼Ç¼£¬REPLACE¾ÍʹÓÃмǼµÄÖµÀ´Ìæ»»ÔÀ´µÄ¼Ç
¼ֵ¡£
ʹÓÃREPLACEµÄ×î´óºÃ´¦¾ÍÊÇ¿ÉÒÔ½«DELETEºÍINSERTºÏ¶þΪһ£¬ÐγÉÒ»¸öÔ×Ó²Ù×÷¡£ÕâÑù¾Í¿ÉÒÔ²»±Ø¿¼ÂÇÔÚͬʱʹÓÃDELETE ºÍ
INSERTʱÌí¼ÓÊÂÎñµÈ¸´ÔÓ²Ù×÷ÁË¡£
ÔÚʹÓÃREPLACEʱ£¬±íÖбØÐëÓÐΨһË÷Òý£¬¶øÇÒÕâ¸öË÷ÒýËùÔÚµÄ×ֶβ»ÄÜÔÊÐí¿ÕÖµ£¬·ñÔòREPLACE¾ÍºÍINSERTÍêȫһÑùµÄ¡£
ÔÚÖ´ÐÐREPLACEºó£¬ÏµÍ³·µ»ØÁËËùÓ°ÏìµÄÐÐÊý£¬Èç¹û·µ»Ø1£¬ËµÃ÷Ô
Ïà¹ØÎĵµ£º
1¡¢±à¼MySQLÅäÖÃÎļþ£º
windows»·¾³ÖУº%MySQL_installdir%\my.ini¡¡//Ò»°ãÔÚMySQL°²×°Ä¿Â¼ÏÂÓÐmy.ini¼´MySQLµÄÅäÖÃÎļþ¡£
linux»·¾³ÖУº/etc/my.cnf
ÔÚ[MySQLd]ÅäÖöÎÌí¼ÓÈçÏÂÒ»ÐУº
skip-grant-tables
±£´æÍ˳ö±à¼¡£
2¡¢È»ºóÖØÆôMySQL·þÎñ
windows»·¾³ÖУº
net stop MySQL
net start MySQL
linux»·¾³ÖУº
/e ......
/**********************by garcon1986***************************************/
´íÎó´úÂëÈçÏ£º
#1045 - Access denied for user 'root'@'localhost' (using password: YES)
$cd /etc/mysql
$mysql -u root -p
³öÏÖ´íÎó#1045
³¢ÊÔÁ˺ܶ෽·¨ºó£¬ÔÚÍøÂçÉÏÕÒµ½Á˽â¾ö·½·¨¡£
$cd /etc/mysql
$gedit debian.cnf
ÕÒµ½ ......
Ò».°²×°
rpm·½Ê½
rpm -ivf MySQL*
tar·½Ê½
tar xzvf mysql-x.xx.tar.gz
cd mysqlp-x.xx Éú³Émakefile
./congigure
make ±àÒë
make install
mysql_install_db
¶þ.Æô¶¯¡¢¹Ø±Õ
ser ......
1.½¨±í¹ý³ÌÈçÏÂ
create database test default character set utf8 collate utf8_general_ci
use test;
create table devicedata
(
ID int auto_increment PRIMARY key ,
TimeStamp datetime,
Device_Name varchar(100),
Tag_Name varchar(100),
Value varchar(50)
)
2 ......
1£ºMysql ÃüÁî²»¿ÉÒÔÖ´ÐÐ
ÔÒò £ººÇºÇ ±ÈÈç show databases µÄÃüÁî £¬Ö´ÐÐÍêÖ®ºó ɶҲûÓÐ £¬×Ðϸ ÕÒÁËÔÒò £¬Oh my god ÉÙÁË ·ÖºÅ¡£
Ӧд³É£ºshow databases;
2£ºÃüÁîÐÐÖÐÎÄÂÒÂëÎÊÌâ
ÏÖÏó£ºmysqlµÄĬÈϱàÂëÉèÖÃΪutf-8£¬Ò³ÃæÒÔutf-8µÄ±àÂ뷽ʽдÈëµ½Êý¾Ý¿â¡£Óù¤¾ß²é¿´Ò»ÇÐÕý³££¬µ«´ÓmysqlµÄÃüÁîÐжÁÊý¾Ý³öÀ´× ......