Normalerweise speichern Sie die ausführliche Ausgabe eines Linux-Befehls wie folgt:
# command > output.txt
Wenn Sie jedoch einen Befehl wie mysqldump
verwenden, wird >
Option gibt den Speicherauszug der Datenbanktabellen in die gewünschte Datei aus:
# mysqldump --username=whatever --password=whatever -h localhost database > dump.sql
Wenn Sie im -v
(ausführlich) Option auf mysqldump
, gibt Hilfeinformationen darüber aus, was der Befehl tut. Wie speichere ich diese ausführliche Ausgabe in einer Datei seit dem >
Option wird verwendet, um die Datenbanktabelleninformationen in eine Datei auszugeben?
Genauer gesagt, ich speichere die Ausgabe einer Datenbank wie folgt in eine andere Datenbank:
mysqldump -alv -h 123.123.123.123 --user=username [email protected] --add-drop-table databasename | mysql --user=username [email protected] -h localhost localdatabase
Ich habe Folgendes versucht, aber die Ausgabedatei war am Ende leer
mysqldump -alv -h 123.123.123.123 --user = Benutzername --password = p @ ssw0rd --add-drop-table Datenbankname | mysql --user = Benutzername --password = p @ ssw0rd -h localhost localdatabase> output.log
Es wurde auch Folgendes versucht, aber die Datenbankinformationen wurden anstelle der Zieldatenbank in die Datei output.log umgeleitet:
mysqldump -alv -h 123.123.123.123 --user=username [email protected] --add-drop-table databasename > output.log | mysql --user=username [email protected] -h localhost localdatabase
Und ich sehe keine Art von --log-file=FILE
Option für mysqldump
entweder.
Ihr 1. mysqldump erstellt Tabellenstrukturen und INSERTs und legt sie in dump.sql ab.
Ihr 2. Dump ist ein Remote-Dump, der direkt in mysql in localhost geleitet wird.
Wenn Sie versuchen, eine Ausgabe aufgrund von Fehlern abzufangen, versuchen Sie Folgendes:
mysqldump -alv -h 123.123.123.123 --user=username [email protected] --add-drop-table databasename 2> output.log | mysql --user=username [email protected] -h localhost localdatabase
Verwenden von 2>
fängt alle fehlerbasierten Ausgaben ab (auch bekannt als stderr). Der mysqldump sollte weiterhin die normale Konsolenausgabe (auch bekannt als stdout) an die andere mysql-Sitzung weiterleiten und die Daten wie beabsichtigt laden.
BEISPIEL: Ich habe eine kleine Datenbank namens sample auf meinem PC.
Ich lief das:
C:\LWDBA>mysqldump -u... -p... --verbose sample 2>sample.txt > sample.sql
C:\LWDBA>type sample.txt
-- Connecting to localhost...
-- Retrieving table structure for table users...
-- Sending SELECT query...
-- Retrieving rows...
-- Disconnecting from localhost...
C:\LWDBA>type sample.sql
-- MySQL dump 10.13 Distrib 5.5.12, for Win64 (x86)
--
-- Host: localhost Database: sample
-- ------------------------------------------------------
-- Server version 5.5.12-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 */;
--
-- Table structure for table `users`
--
DROP TABLE IF EXISTS `users`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`users_tbl_points` int(11) NOT NULL,
`users_tbl_rank` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `users_tbl_points` (`users_tbl_points`)
) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `users`
--
LOCK TABLES `users` WRITE;
/*!40000 ALTER TABLE `users` DISABLE KEYS */;
INSERT INTO `users` VALUES (1,785523,9),(2,443080,20),(3,858830,7),(4,964909,3),(5,248056,24),
(6,345553,21),(7,983596,2),(8,881325,6),(9,455836,19),(10,635204,16),(11,808514,8),
(12,136960,28),(13,259255,22),(14,885399,5),(15,649229,15),(16,589948,18),(17,2055,30),
(18,240429,25),(19,195981,26),(20,258620,23),(21,705158,12),(22,749931,11),(23,634182,17),
(24,921117,4),(25,703038,13),(26,751842,10),(27,650093,14),(28,994943,1),(29,24437,29),
(30,137355,27);
/*!40000 ALTER TABLE `users` 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 2012-03-02 15:49:54
C:\LWDBA>
Versuche es !!!
mysqldump -v gibt an den stderr-Stream aus, sodass Sie dies nur umleiten müssen
mysqldump -alv -h 123.123.123.123 --user=username [email protected] --add-drop-table databasename 2> dump.log | mysql --user=username [email protected] -h localhost localdatabase
beispiel
[email protected]: ~ > mysqldump -v -u root mysql > /dev/null 2> output.log
[email protected]: ~ > cat output.log
-- Connecting to localhost...
-- Retrieving table structure for table columns_priv...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table db...