ä¸ çå¤
      å¨ä¸ä¸¤ç¯æç« ï¼MySQLå¤ä»½ä¸æ¢å¤ä¹å·å¤ï¼MySQLå¤ä»½ä¸æ¢å¤ä¹çå®ç¯å¢ä½¿ç¨å·å¤ï¼ä¸ï¼æ们æå°äºå·å¤åçå®ç¯å¢ä¸ä½¿ç¨å·å¤ãé£ä»è¿ç¯æç« å¼å§æ们çä¸çå¤ãæ¾ç¶çå¤åå·å¤æ¯ä¸¤ä¸ªç¸å¯¹çæ¦å¿µï¼å·å¤æ¯ææ°æ®åºæå¡ï¼æ¯å¦MySQLï¼Oracleåä¸æ¥ï¼ç¶å使ç¨æ·è´ãæå æè å缩å½ä»¤å¯¹æ°æ®ç®å½è¿è¡å¤ä»½ï¼é£ä¹æ们å¾å®¹ææ³å°çå¤å°±æ¯å¨MySQLæè å ¶ä»æ°æ®åºæå¡å¨è¿è¡çæ åµä¸è¿è¡å¤ä»½ãä½æ¯ï¼è¿éåå¨ä¸ä¸ªé®é¢ï¼å 为ç产åºå¨è¿è¡çæ åµä¸ï¼æ对该åºç读åï¼è¯»åé¢çæå¯è½é«ï¼ä¹å¯è½ä½ï¼ä¸ç®¡é¢çé«ä½ï¼æ»ä¼å°±ä¼é æå¤ä»½åºæ¥çæ°æ®åç产åºä¸çæ°æ®ä¸ä¸è´çæ åµãçå¤è¿æ®µæ¶é´ï¼å ¶ä»äººä¸å¯ä»¥æä½æ¯ä¸ç°å®çï¼å ä¸ºä½ æ»ä¸å¯è½ç»æ¢ç¨æ·è®¿é®Webç¨åºãè¦è§£å³è¿ä¸ªé®é¢ï¼å¯ä»¥éç¨æå®å¤ä»½çç¥ï¼æ¯å¦åªä¸ªæ¶é´æ®µè¿è¡å¤ä»½ï¼å¤ä»½åªäºæ°æ®ççï¼æ»ä¹ï¼ä¿è¯æ°æ®çå®æ´æ§åä¸è´æ§ï¼åè®°ï¼å¤ä»½éäºä¸åï¼ï¼ï¼
Â
      çå¤éç¨çæ¯ä½¿ç¨mysqldumpå½ä»¤è¿è¡å¤ä»½ï¼æ¤å·¥å ·æ¯MySQLå ç½®çå¤ä»½åæ¢å¤å·¥å ·ï¼åè½å¼ºå¤§ï¼å®å¯ä»¥å¯¹æ´ä¸ªåºè¿è¡å¤ä»½ï¼å¯ä»¥å¯¹å¤ä¸ªåºè¿è¡å¤ä»½ï¼å¯ä»¥å¯¹åå¼ è¡¨æè æå å¼ è¡¨è¿è¡å¤ä»½ãä½æ¯æ æ³åæ¶å¤ä»½å¤ä¸ªåºå¤ä¸ªè¡¨ï¼åªæåå¼å¤ä»½ãä¸é¢æ们çä¸çå¤ç示æå¾ï¼å¹¶è¿è¡çå¤æ¨¡æã
Â
äº ç¤ºæå¾
Â
ä¸ çå¤æ¨¡æ
对å个åºè¿è¡å¤ä»½
第ä¸æ¥ï¼ç§»é¤LVMå¿«ç §ãï¼å¦æ没æå建ï¼å¿½ç¥æ¤æ¥ï¼
[[email protected] data]# lvremove /dev/data/smydata Do you really want to remove active logical volume smydata? [y/n]: y Logical volume "smydata" successfully removed
Â
第äºæ¥ï¼è®¾ç½®MySQLçå¯ç
mysql> set password=password("123456"); Query OK, 0 rows affected (0.00 sec)
Â
第ä¸æ¥ï¼æ¥çMySQLæ¯å¦å¯å¨ãå 为æ¯çå¤ï¼æ以è¦æ±MySQLæå¡å¯å¨
[[email protected] data]# /etc/init.d/mysqld status SUCCESS! MySQL running (2664)
第åæ¥ï¼å¯¼åºå个æ°æ®åº
[[email protected] data]# cd /databackup/ #æ¬è´¨æ¯å¯¼åºä¸ºSQL [[email protected] databackup]# mysqldump -uroot -p123456 --database larrydb -- MySQL dump 10.13 Distrib 5.5.29, for Linux (x86_64) -- -- Host: localhost Database: larrydb -- ------------------------------------------------------ -- Server version 5.5.29-log /*!40101 SET @[email protected]@CHARACTER_SET_CLIENT */; /*!40101 SET @[email protected]@CHARACTER_SET_RESULTS */; /*!40101 SET @[email protected]@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */; /*!40103 SET @[email protected]@TIME_ZONE */; /*!40103 SET TIME_ZONE='+00:00' */; /*!40014 SET @[email protected]@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; /*!40014 SET @[email protected]@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; /*!40101 SET @[email protected]@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; /*!40111 SET @[email protected]@SQL_NOTES, SQL_NOTES=0 */; -- -- Current Database: `larrydb` -- CREATE DATABASE /*!32312 IF NOT EXISTS*/ `larrydb` /*!40100 DEFAULT CHARACTER SET latin1 */; USE `larrydb`; -- -- Table structure for table `class` -- DROP TABLE IF EXISTS `class`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `class` ( `cid` int(11) DEFAULT NULL, `cname` varchar(30) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Dumping data for table `class` -- LOCK TABLES `class` WRITE; /*!40000 ALTER TABLE `class` DISABLE KEYS */; INSERT INTO `class` VALUES (1,'linux'),(2,'oracle'); /*!40000 ALTER TABLE `class` ENABLE KEYS */; UNLOCK TABLES; -- -- Table structure for table `stu` -- DROP TABLE IF EXISTS `stu`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `stu` ( `sid` int(11) DEFAULT NULL, `sname` varchar(30) DEFAULT NULL, `cid` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Dumping data for table `stu` -- LOCK TABLES `stu` WRITE; /*!40000 ALTER TABLE `stu` DISABLE KEYS */; INSERT INTO `stu` VALUES (1,'larry01',1),(2,'larry02',2); /*!40000 ALTER TABLE `stu` ENABLE KEYS */; UNLOCK TABLES; /*!40103 SET [email protected]_TIME_ZONE */; /*!40101 SET [email protected]_SQL_MODE */; /*!40014 SET [email protected]_FOREIGN_KEY_CHECKS */; /*!40014 SET [email protected]_UNIQUE_CHECKS */; /*!40101 SET [email protected]_CHARACTER_SET_CLIENT */; /*!40101 SET [email protected]_CHARACTER_SET_RESULTS */; /*!40101 SET [email protected]_COLLATION_CONNECTION */; /*!40111 SET [email protected]_SQL_NOTES */; Dump completed on 2013-09-10 18:56:06 #å°è¾åºç»æä¿åå°æä»¶ä¸ [[email protected] databackup]# mysqldump -uroot -p123456 --database larrydb > larrydb.sql
第äºæ¥ï¼æ¨¡ææ°æ®ä¸¢å¤±ï¼è¿å ¥MySQLï¼å é¤æ°æ®åº
[[email protected] data]# mysql -uroot -p123456 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.5.29-log Source distribution Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | crm | | game | | hello | | larrydb | | mnt | | mysql | | performance_schema | | test | +--------------------+ 9 rows in set (0.00 sec) mysql> drop database larrydb; Query OK, 2 rows affected (0.01 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | crm | | game | | hello | | mnt | | mysql | | performance_schema | | test | +--------------------+ 8 rows in set (0.00 sec) mysql> exit Bye
第å æ¥ï¼å¯¼å ¥æ°æ®
[[email protected] databackup]# mysql -uroot -p123456 <larrydb.sql
Â
第ä¸æ¥ï¼ç»å½MySQLï¼æ¥çæ°æ®æ¯å¦æ£å¸¸
[[email protected] data]# mysql -uroot -p123456 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 6 Server version: 5.5.29-log Source distribution Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show database; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'database' at line 1 mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | crm | | game | | hello | | larrydb | | mnt | | mysql | | performance_schema | | test | +--------------------+ 9 rows in set (0.00 sec) mysql> use larrydb; Database changed mysql> select * from class; +------+--------+ | cid | cname | +------+--------+ | 1 | linux | | 2 | oracle | +------+--------+ 2 rows in set (0.00 sec) mysql> select * from stu; +------+---------+------+ | sid | sname | cid | +------+---------+------+ | 1 | larry01 | 1 | | 2 | larry02 | 2 | +------+---------+------+ 2 rows in set (0.00 sec)
对å¤ä¸ªåºè¿è¡å¤ä»½
第ä¸æ¥ï¼æ¥çæåªäºæ°æ®åº
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | crm | | game | | hello | | larrydb | | mnt | | mysql | | performance_schema | | test | +--------------------+ 9 rows in set (0.00 sec) mysql> use game; Database changed mysql> show tables; +----------------+ | Tables_in_game | +----------------+ | country | | fight | | hero | +----------------+ 3 rows in set (0.00 sec) mysql> select * from country; +-----+---------+----------+ | cno | cname | location | +-----+---------+----------+ | 10 | caowei | luoyang | | 20 | shuhan | chengdou | | 30 | sunwu | nanjing | | 40 | houhan | luoyang | | 50 | beisong | kaifeng | | 60 | éå½ | æ´é³ | +-----+---------+----------+ 6 rows in set (0.00 sec)
第äºæ¥ï¼å¤ä»½å¤ä¸ªåº
[[email protected] databackup]# mysqldump -uroot -p123456 --databases larrydb game > larrydb_game.sql [[email protected] databackup]# ll larrydb_game.sql -rw-r--r--. 1 root root 6159 Sep 10 19:05 larrydb_game.sql
第ä¸æ¥ï¼æ¨¡ææ°æ®ä¸¢å¤±ã
mysql> drop database game; Query OK, 3 rows affected (0.01 sec) mysql> drop database larrydb; Query OK, 2 rows affected (0.00 sec) mysql> use crm; Database changed mysql> show tables; +---------------+ | Tables_in_crm | +---------------+ | test | +---------------+ 1 row in set (0.00 sec) mysql> select * from test; Empty set (0.00 sec) mysql> drop database crm; Query OK, 1 row affected (0.00 sec)
第åæ¥ï¼æ¢å¤æ°æ®
[[email protected] databackup]# mysql -uroot -p123456 < larrydb_game.sql
Â
第äºæ¥ï¼æ¥çæ°æ®æ¯å¦æ£å¸¸
[[email protected] data]# mysql -uroot -p123456 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 5.5.29-log Source distribution Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | game | | hello | | larrydb | | mnt | | mysql | | performance_schema | | test | +--------------------+ 8 rows in set (0.00 sec) mysql> use game; Database changed mysql> select * from country; +-----+---------+----------+ | cno | cname | location | +-----+---------+----------+ | 10 | caowei | luoyang | | 20 | shuhan | chengdou | | 30 | sunwu | nanjing | | 40 | houhan | luoyang | | 50 | beisong | kaifeng | | 60 | éå½ | æ´é³ | +-----+---------+----------+ 6 rows in set (0.00 sec) mysql> use larrydb; Database changed mysql> select * from class; +------+--------+ | cid | cname | +------+--------+ | 1 | linux | | 2 | oracle | +------+--------+ 2 rows in set (0.00 sec)
Â
å¤ä»½ææçåº
[[email protected] databackup]# mysqldump --help | grep all-database OR mysqldump [OPTIONS] --all-databases [OPTIONS] -A, --all-databases Dump all the databases. This will be same as --databases --databases= or --all-databases), the logs will be --all-databases or --databases is given. all-databases FALSE [[email protected] databackup]# mysqldump -uroot -p123456 --all-databases > all_databases.sql [[email protected] databackup]# ll all_databases.sql -h -rw-r--r--. 1 root root 506K Sep 10 19:16 all_databases.sql
å¤ä»½æå¼ è¡¨æè æå å¼ è¡¨
第ä¸æ¥ï¼å¤ä»½æå¼ è¡¨åæå å¼ è¡¨
[[email protected] databackup]# mysqldump game hero country -uroot -p123456 > game_hero_country.sql [[email protected] databackup]# ll game_hero_country.sql -rw-r--râ. 1 root root 3955 Sep 10 19:11 game_hero_country.sql
第äºæ¥ï¼æ¨¡ææ°æ®ä¸¢å¤±
mysql> use game; Database changed mysql> show tables; +----------------+ | Tables_in_game | +----------------+ | country | | fight | | hero | +----------------+ 3 rows in set (0.00 sec) mysql> drop table hero; Query OK, 0 rows affected (0.00 sec) mysql> drop table country; Query OK, 0 rows affected (0.00 sec)
Â
第ä¸æ¥ï¼æ¥çæ°æ®æ¯å¦æ£å¸¸
[[email protected] databackup]# mysql -uroot -p123456 < game_hero_country.sql ERROR 1046 (3D000) at line 22: No database selected [[email protected] databackup]# mysql -uroot -p123456 --database game < game_hero_country.sql [[email protected] databackup]# mysql -uroot -p123456 -e "select * from game.country" +-----+---------+----------+ | cno | cname | location | +-----+---------+----------+ | 10 | caowei | luoyang | | 20 | shuhan | chengdou | | 30 | sunwu | nanjing | | 40 | houhan | luoyang | | 50 | beisong | kaifeng | | 60 | éå½ | æ´é³ | +-----+---------+----------+
å ç¸å ³é 读
- MySQLå¤ä»½ä¸æ¢å¤ä¹å·å¤
- MySQLå¤ä»½ä¸æ¢å¤ä¹çå®ç¯å¢ä½¿ç¨å·å¤
æçé®ç®±ï¼[email protected] æ°æµªå¾®åï¼@jutdb å¾®ä¿¡å ¬ä¼å¹³å°ï¼JustOracleï¼å¾®ä¿¡å·ï¼justoracleï¼ æ°æ®åºææ¯äº¤æµç¾¤ï¼336882565ï¼å 群æ¶éªè¯ From CSDN XXXï¼ All is well 2013å¹´11æ9æ¥ By Larry Wen
 | |
@Wentasy åæä» ä¾åèï¼æ¬¢è¿å¤§å®¶æ¥è®¿ãå¦æé误ä¹å¤ï¼å¸ææ¹è¯ææ£ãåååæå¦é转载请注æåºå¤ï¼è°¢è°¢ :) [CSDNå客] |