炫意html5
最早CSS3和HTML5移动技术网站之一

使用python 导入数据库时 遇到的问题 写的有点长 希望大佬能帮忙看看

先看代码

    import os
import time
BACKUP_PATH = r'C:/Users/Administrator/Desktop/English_learning_assistant/bakcup/'
DATETIME = time.strftime('%Y-%m-%d')
# print(DATETIME)
TODAYBACKUPPATH = BACKUP_PATH + DATETIME
if not os.path.exists(TODAYBACKUPPATH):
os.makedirs(TODAYBACKUPPATH)
# dumpcmd = "mysqldump -uroot -p123456 test1 > " + TODAYBACKUPPATH + "/test2.sql"
# print("数据已备份到"+BACKUP_PATH)
# os.system(dumpcmd)
dumpcmd = "mysqldump -uroot -p123456 test1 < " + TODAYBACKUPPATH + "/test2.sql"
os.system(dumpcmd)
print(TODAYBACKUPPATH)
print(dumpcmd)
print("数据已恢复")

这是错误

    -- MySQL dump 10.13  Distrib 5.5.53, for Win64 (AMD64)
--
-- Host: localhost    Database: test1
-- ------------------------------------------------------
-- Server version	5.5.53-log
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `test1`
--
DROP TABLE IF EXISTS `test1`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `test1` (
`test1` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `test1`
--
LOCK TABLES `test1` WRITE;
/*!40000 ALTER TABLE `test1` DISABLE KEYS */;
INSERT INTO `test1` VALUES ('');
/*!40000 ALTER TABLE `test1` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2021-05-16 17:31:55
C:/Users/Administrator/Desktop/English_learning_assistant/bakcup/2021-05-16
mysqldump -uroot -p123456 test1 < C:/Users/Administrator/Desktop/English_learning_assistant/bakcup/2021-05-16/test2.sql
数据已恢复

这是 .sql的内容
— MySQL dump 10.13 Distrib 5.5.53, for Win64 (AMD64)

— Host: localhost Database: test1
— ——————————————————
— Server version 5.5.53-log
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT /;
/
!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS /;
/
!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION /;
/
!40101 SET NAMES utf8 /;
/
!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE /;
/
!40103 SET TIME_ZONE=’+00:00′ /;
/
!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 /;
/
!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 /;
/
!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE=’NO_AUTO_VALUE_ON_ZERO’ /;
/
!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 /;

— Table structure for table test1

DROP TABLE IF EXISTS test1;
/
!40101 SET @saved_cs_client = @@character_set_client /;
/
!40101 SET character_set_client = utf8 /;
CREATE TABLE test1 (
test1 varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/
!40101 SET character_set_client = @saved_cs_client /;

— Dumping data for table test1

LOCK TABLES test1 WRITE;
/
!40000 ALTER TABLE test1 DISABLE KEYS /;
INSERT INTO test1 VALUES (‘2333’);
/
!40000 ALTER TABLE test1 ENABLE KEYS /;
UNLOCK TABLES;
/
!40103 SET TIME_ZONE=@OLD_TIME_ZONE /;
/
!40101 SET SQL_MODE=@OLD_SQL_MODE /;
/
!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS /;
/
!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS /;
/
!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT /;
/
!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS /;
/
!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION /;
/
!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
— Dump completed on 2021-05-16 17:39:56

这是数据库

我猜错误的原因是这个

VALUES(”)这里面是空的

哪位大佬帮忙看一下啊 多谢了

回答

发现了问题所在 有两点:

恢复的SQL命令是 mysql -uroot -p123456 test1 < ” + TODAYBACKUPPATH + “/test2.sql

在恢复前需要先关闭数据库

炫意HTML5 » 使用python 导入数据库时 遇到的问题 写的有点长 希望大佬能帮忙看看

Java基础教程Android基础教程