MySQL±¸·ÝºÍ»Ö¸´Êý¾Ý±íµÄ·½·¨
¹Ø¼ü´Ê£ºMySQL ±¸·Ý »Ö¸´
¡¡¡¡±¸·ÝÊÇ×î¼òµ¥µÄ±£»¤Êý¾ÝµÄ·½·¨£¬±¾½Ú½«½éÉܶàÖÖ±¸·Ý·½·¨¡£ÎªÁ˵õ½Ò»¸öÒ»Öµı¸·Ý£¬ÔÚÏà¹ØµÄ±íÉÏ×öÒ»¸öLOCK TABLES£¬ÄãÖ»ÐèÒ»¸ö¶ÁËø¶¨£¬µ±ÄãÔÚÊý¾Ý¿âĿ¼ÖÐ×öÎļþµÄÒ»¸ö¿½±´Ê±£¬ÕâÔÊÐíÆäËûÏ̼߳ÌÐø²éѯ¸Ã±í;µ±Äã»Ö¸´Êý¾Ýʱ£¬ÐèÒªÒ»¸öдËø¶¨£¬ÒÔ±ÜÃâ³åÍ»¡£
¡¡¡¡Ê¹ÓÃSQLÓï¾ä±¸·ÝºÍ»Ö¸´
¡¡¡¡Äã¿ÉÒÔʹÓÃSELECT INTO OUTFILEÓï¾ä±¸·ÝÊý¾Ý£¬²¢ÓÃLOAD DATA INFILEÓï¾ä»Ö¸´Êý¾Ý¡£ÕâÖÖ·½·¨Ö»Äܵ¼³öÊý¾ÝµÄÄÚÈÝ£¬²»°üÀ¨±íµÄ½á¹¹£¬Èç¹û±íµÄ½á¹¹ÎļþË𻵣¬Äã±ØÐëÒªÏȻָ´ÔÀ´µÄ±íµÄ½á¹¹¡£
¡¡¡¡Óï·¨£º
¡¡¡¡SELECT * INTO {OUTFILE | DUMPFILE} 'file_name' from tbl_name
¡¡¡¡LOAD DATA [LOW_PRIORITY] [LOCAL] INFILE 'file_name.txt' [REPLACE | IGNORE]
¡¡¡¡INTO TABLE tbl_name
¡¡¡¡SELECT ... INTO OUTFILE 'file_name'¸ñʽµÄSELECTÓï¾ä½«Ñ¡ÔñµÄÐÐдÈëÒ»¸öÎļþ¡£ÎļþÔÚ·þÎñÆ÷Ö÷»úÉϱ»´´½¨£¬²¢ÇÒ²»ÄÜÊÇÒѾ´æÔÚµÄ(²»¹Ü±ðµÄ£¬Õâ¿É×èÖ¹Êý¾Ý¿â±íºÍÎļþÀýÈç“/etc/passwd”±»ÆÆ»µ)¡£SELECT ... INTO OUTFILEÊÇLOAD DATA INFILEÄæ²Ù×÷¡£
¡¡¡¡LOAD DATA INFILEÓï¾ä´ÓÒ»¸öÎı¾ÎļþÖÐÒԺܸߵÄËٶȶÁÈëÒ»¸ö±íÖС£Èç¹ûÖ¸¶¨LOCAL¹Ø¼ü´Ê£¬´Ó¿Í»§Ö÷»ú¶ÁÎļþ¡£Èç¹ûLOCALûָ¶¨£¬Îļþ±ØÐëλÓÚ·þÎñÆ÷ÉÏ¡£(LOCALÔÚMySQL3.22.6»òÒÔºó°æ±¾ÖпÉÓá£)
¡¡¡¡ÎªÁË°²È«ÔÒò£¬µ±¶ÁȡλÓÚ·þÎñÆ÷ÉϵÄÎı¾Îļþʱ£¬Îļþ±ØÐë´¦ÓÚÊý¾Ý¿âĿ¼»ò¿É±»ËùÓÐÈ˶ÁÈ¡¡£ÁíÍ⣬ΪÁ˶ԷþÎñÆ÷ÉÏÎļþʹÓÃLOAD DATA INFILE£¬ÔÚ·þÎñÆ÷Ö÷»úÉÏÄã±ØÐëÓÐfileµÄȨÏÞ¡£Ê¹ÓÃÕâÖÖSELECT INTO OUTFILEÓï¾ä£¬ÔÚ·þÎñÆ÷Ö÷»úÉÏÄã±ØÐëÓÐFILEȨÏÞ¡£
¡¡¡¡ÎªÁ˱ÜÃâÖظ´¼Ç¼£¬ÔÚ±íÖÐÄãÐèÒªÒ»¸öPRIMARY KEY»òUNIQUEË÷Òý¡£µ±ÔÚΨһË÷ÒýÖµÉÏÒ»¸öмǼÓëÒ»¸öÀϼǼÖظ´Ê±£¬REPLACE¹Ø¼ü´ÊʹµÃÀϼǼÓÃÒ»¸öмǼÌæ´ú¡£Èç¹ûÄãÖ¸¶¨IGNORE£¬Ìø¹ýÓÐΨһË÷ÒýµÄÏÖÓÐÐеÄÖظ´ÐеÄÊäÈë¡£Èç¹ûÄã²»Ö¸¶¨ÈκÎÒ»¸öÑ¡Ïµ±ÕÒµ½Öظ´Ë÷Òýֵʱ£¬³öÏÖÒ»¸ö´íÎ󣬲¢ÇÒÎı¾ÎļþµÄÓàϲ¿·Ö±»ºöÂÔʱ¡£
¡¡¡¡Èç¹ûÄãÖ¸¶¨¹Ø¼ü´ÊLOW_PRIORITY£¬LOAD DATAÓï¾äµÄÖ´Ðб»ÍƳٵ½Ã»ÓÐÆäËû¿Í»§¶ÁÈ¡±íºó¡£
¡¡¡¡Ê¹ÓÃLOCAL½«±ÈÈ÷þÎñÆ÷Ö±½Ó´æÈ¡ÎļþÂýЩ£¬ÒòΪÎļþµÄÄÚÈݱØÐë´Ó¿Í»§Ö÷»ú´«Ë͵½·þÎñÆ÷Ö÷»ú¡£ÔÚÁíÒ»·½Ã棬Äã²»ÐèÒªfileȨÏÞ×°Ôر¾µØÎļþ¡£Èç¹ûÄãʹÓÃLOCAL¹Ø¼ü´Ê´ÓÒ»¸ö±¾µØÎļþ×°ÔØÊý¾Ý£¬·þÎñÆ÷ûÓа취ÔÚ²Ù×÷µÄµ±ÖÐÍ£Ö¹ÎļþµÄ´«Ê䣬Òò´ËȱʡµÄÐÐΪºÃÏñIGNORE±»Ö¸¶¨Ò»Ñù¡£
¡¡¡¡µ±ÔÚ·þÎñÆ
Ïà¹ØÎĵµ£º
/*ÑÝʾһ¸öJDBC³ÌÐò£¬´ÓMysqlµÄLMDÊý¾Ý¿âÖжÁ³ö±íadminµÄÒ»¸öÐÅÏ¢*/
import java.sql.*;
public class TestMysqlConnection {
public static void main(String[] args) {
Connection conn = null;
Statement stmt = ......
ÒÔϵÄÎÄÕÂÊÇMySQL grantÓï·¨µÄÏêϸ½âÎö£¬Èç¹ûÄã¶ÔMySQL grantÓï·¨µÄÏà¹ØµÄʵ¼Ê²Ù×÷ÓÐÐËȤµÄ»°£¬Äã¾Í¿ÉÒÔ¶ÔÒÔϵÄÎÄÕµã»÷¹Û¿´ÁË¡£ÎÒÃÇ´ó¼Ò¶¼ÖªµÀMySQLÊý¾Ý¿â¸³ÓèÓû§È¨ÏÞÃüÁîµÄ¼òµ¥¸ñʽ¿É¸ÅÀ¨Îª£º
grant ȨÏÞ on Êý¾Ý¿â¶ÔÏó to Óû§
Ò»¡¢grant ÆÕͨÊý¾ÝÓû§£¬²éѯ¡¢²åÈë¡¢¸üС¢É¾³ý Êý¾Ý¿âÖÐËùÓбíÊý¾ÝµÄȨÀû¡£
grant ......
¸ømysql¿ªÒ»¸ö¿ÉÒÔÔ¶³Ì·ÃÎʵÄÓû§ÃüÁîÈçÏÂ:
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
"*.*" ±íʾÊý¾Ý¿âÖÐËùÓеıí,Ò²¿ÉÒÔ»»³ÉÖ¸¶¨µÄ±íÈçtest.*
"myuser" ±íʾµÄÊÇ·ÃÎʵÄÓû§Ãû;
"%" ±íʾËùÓеÄÖ÷»ú¼´ÈκεÄÖ÷»ú¶¼¿ÉÒÔͨ¹ýÕâ¸öÓû§Ãû·ÃÎÊÎÒµÄÊý¾Ý¿â,Ò²¿ÉÒԸóÉÌض¨µ ......
×òÌìÒªmysqlÖÐд´æ´¢¹ý³Ì·¢ÏÖÍøÉÏÓйØÓÚcursorÑ»·ÇÒÌ×µÄ×ÊÁϺÜÉÙ,ÏÖ·¢³ö±¾ÈËдµÄÀý×Ó,Ï£ÍûÄܶԴó¼ÒÓаïÖú.
¿´ÕÐ:
DELIMITER $$
USE `ad_db`$$
DROP PROCEDURE IF EXISTS `test`$$
CREATE DEFINER=`root`@`%` PROCEDURE `test`()
BEGIN
/** CPAЧ¹ûÊý */
DECLARE _tmpId1 INT;
DECLARE ......
¹ØÓÚMySqlµÄµ¼Èëµ¼³öÎÊÌâ
ÔÚÖÕ¶ËÖУ¬½øÈëmysqlµÄ·¾¶ÏµÄbinÖУ¬ÔÚÕâ¸ö·¾¶Ï¿ÉÒÔÖ´ÐÐmysql£¬mysqldumpµÈÃüÁî¡£
»òÕßÌí¼Ó»·¾³±äÁ¿ ÉèÖû·¾³±äÁ¿path "...(mysqlµÄ°²×°Â·¾¶ÏµÄbinĿ¼)"£¬ÕâÑù¾Í²»±Øÿ´Î¶¼½øÈëÉÏÃæËù˵µÄ·¾¶Ï²Ù×÷¡£
µ¼³öÒ»¸ö¿â£º
mysqldump ......