DatabaseError:文件已加密或不是数据库

时间:2015-12-23 12:09:24

标签: python sqlite spyder

我试图用我的代码连接我的.sql数据库和python版本2.7.9:

 import sqlite3
db = sqlite3.connect("c:\\Users\\afsoon\\Desktop\\ch9learning\\sql\\genres.sql")
cursor = db.cursor()
query = """SELECT * FROM mytable where genre='folk'"""
lines = cursor.execute(query)
data = cursor.fetchall()
db.close()

但我发现了这个错误:

lines = cursor.execute(query)
Traceback (most recent call last):

  File "<ipython-input-10-af02982f9f74>", line 1, in <module>
    lines = cursor.execute(query)

DatabaseError: file is encrypted or is not a database

我在Windows上,我有sqlite3!

你知道我该怎么办? 提前感谢一堆:)

p.s:这些是我的数据库第一行

-- phpMyAdmin SQL Dump
-- version 4.5.1
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Dec 23, 2015 at 09:29 AM
-- Server version: 10.1.9-MariaDB
-- PHP Version: 5.6.15

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!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 utf8mb4 */;

--
-- Database: `genres`
--
CREATE DATABASE IF NOT EXISTS `genres` DEFAULT CHARACTER SET utf8 COLLATE utf8_persian_ci;
USE `genres`;

-- --------------------------------------------------------

--
-- Table structure for table `mytable`
--

CREATE TABLE `mytable` (
  `genre` varchar(640) COLLATE utf8_persian_ci DEFAULT NULL,
  `track_id` varchar(50) COLLATE utf8_persian_ci DEFAULT NULL,
  `artist_name` varchar(248) COLLATE utf8_persian_ci DEFAULT NULL,
  `title` varchar(248) COLLATE utf8_persian_ci DEFAULT NULL,
  `keyy` decimal(13,10) DEFAULT NULL,
  `modee` decimal(13,10) DEFAULT NULL,
  `duration` decimal(14,10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_persian_ci;

--
-- Dumping data for table `mytable`

1 个答案:

答案 0 :(得分:2)

您必须将数据导入SQLite。由于您的文件是MySQL的导出,因此可能存在导入问题,您可能需要手动修复某些行。

但基本上你必须创建一个新的SQLite数据库文件并导入你的SQL。你需要sqlite3二进制文件。在命令行上运行:

sqlite3 your_new_db.sqlite
sqlite> .read genres.sql