MYSQLÖÐµÄ constraint Óë CONSTRAINT
һֱϰ¹ßʹÓÃСдµÄSQL±£Áô×Ö£¬Ã»Ïëµ½½ñÌì¾ÓÈ»Óöµ½ÁËÂé·³¹þ£¡£¡ºÍгһÏÂMYSQLÀ²£¡
»·¾³£ºServer version: 5.1.37-1ubuntu5 (Ubuntu)
alter table child_table_name
add constraint constraint_name
foreign key (column_1)
references reference_table_name(reference_column_1);
ºÍ
ALTER TABLE child_table_name
ADD CONSTRAINT constraint_name
FOREIGN KEY (column_1)
REFERENCES reference_table_name(reference_column_1);
²úÉúµÄ½á¹û¾ÓÈ»²»Ò»Ñù¡£
ÓÃshow create table child_table_name;²é¿´
½á¹ûÈçÏ£º
СдµÄconstraint£º
...
KEY `constraint_name
` (`column_1`),
CONSTRAINT `child_table_name_ibfk_1
` FOREIGN KEY (`column_1`) REFERENCES ` reference_table_name` (`reference_column_1`) ON DELETE CASCADE
...
´óдµÄCONSTRAINT£º
...
KEY `constraint_name
` (`column_1`),
CONSTRAINT `constraint_name
` FOREIGN KEY (`column_1`)
REFERENCES ` reference_table_name` (`reference_column_1`) ON DELETE
CASCADE
...
ÔÙºÍгһÏÂMYSQL£¡
Ïà¹ØÎĵµ£º
´æ´¢ÒýÇæÊÇʲô
MySQLÖеÄÊý¾ÝÓø÷ÖÖ²»Í¬µÄ¼¼Êõ´æ´¢ÔÚÎļþ(»òÕßÄÚ´æ)ÖС£ÕâЩ¼¼ÊõÖеÄÿһÖÖ¼¼Êõ¶¼Ê¹Óò»Í¬µÄ´æ´¢»úÖÆ¡¢Ë÷Òý¼¼ÇÉ¡¢Ëø¶¨Ë®Æ½²¢ÇÒ×îÖÕÌṩ¹ã·ºµÄ²»Í¬µÄ¹¦ÄܺÍÄÜÁ¦¡£Í¨¹ýÑ¡Ôñ²»Í¬µÄ¼¼Êõ£¬ÄãÄܹ»»ñµÃ¶îÍâµÄËٶȻòÕß¹¦ÄÜ£¬´Ó¶ø¸ÄÉÆÄãµÄÓ¦ÓõÄÕûÌ幦ÄÜ¡£
ÀýÈ磬Èç¹ûÄãÔÚÑо¿´óÁ¿µÄÁÙʱÊý¾Ý£¬ÄãÒ²ÐíÐèҪʹÓÃÄÚ´æ ......
°²×°ºÃmysqlºó£¬ÔÚʹÓÃmysqʱ£¬³öÏÖÁËÈçÏÂÎÊÌâ.
java.sql.SQLException: Communication failure during handshake. Is there a server running on localhost:3306?
at org.gjt.mm.mysql.MysqlIO.init(MysqlIO.java:327)
at org.gjt.mm.mysql.Connection.connectionInit(Connection.java:261)
at org.gjt.mm.mysql.jdbc2 ......
MySQL ÃüÁîÐÐ
µÚÒ»ÕС¢mysql·þÎñµÄÆô¶¯ºÍÍ£Ö¹
net stop mysql
net start mysql
µÚ¶þÕС¢µÇ½mysql
Óï·¨ÈçÏ£º mysql -uÓû§Ãû -pÓû§ÃÜÂë
¼üÈëÃüÁîmysql -uroot -p£¬ »Ø³µºóÌáʾÄãÊäÈëÃÜÂ룬ÊäÈë12345£¬È»ºó»Ø³µ¼´¿É½øÈëµ½mysqlÖÐÁË£¬mysqlµÄÌáʾ·ûÊÇ£º
mysql>
×¢Ò⣬Èç¹ûÊÇÁ¬½Óµ½ÁíÍâµÄ»úÆ÷ÉÏ£¬ÔòÐèÒª¼ÓÈëÒ»¸ö² ......
MYSQLÊý¾Ý¿âÖеij£ÓÃSQLÓï¾ä
1¡¢SELECT ²éѯÓï¾äºÍÌõ¼þÓï¾ä
SELECT ²éѯ×ֶΠfrom ±íÃû WHERE Ìõ¼þ
²éѯ×ֶΣº¿ÉÒÔʹÓÃͨÅä·û* ¡¢×Ö¶ÎÃû¡¢×ֶαðÃû
±íÃû£º Êý¾Ý¿â.±íÃû £¬±íÃû
³£ÓÃÌõ¼þ£º = µÈÓÚ ¡¢<>²»µÈÓÚ¡¢in °üº¬ ¡¢&nb ......
show variables like 'character%';²é¿´×Ö·û±àÂë
--¸ü¸Ä×Ö·û¼¯
SET character_set_client = utf-8 ;
SET character_set_connection = utf-8 ;
SET character_set_database = utf-8 ;
SET character_set_results = utf-8 ;
SET character_set_server = utf-8 ;
SET collation_connection = utf8 ;
SET colla ......