#1064 插入错误 [英] #1064 error with INSERT INTO

查看:39
本文介绍了#1064 插入错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通过在 phpMyAdmin 中使用导出生成的 PHP 脚本.尝试从该脚本的其他地方导入时,我遇到了各种错误.多亏了这个站点,我才设法将其修改为这个站点,并在出现错误之前进一步了解,但我找不到有关此站点的帮助.

I have a PHP script produced by using Export in phpMyAdmin. When trying to Import elsewhere from that script I got all sort of errors. Thanks to this site I managed to modify it to this one and get further before an error crops up but I can't find help for this one.

原始导出

-- phpMyAdmin SQL Dump
-- version 4.2.5
-- http://www.phpmyadmin.net
--
-- Host: localhost:3306
-- Generation Time: Feb 23, 2015 at 05:23 PM
-- Server version: 5.0.95-log
-- PHP Version: 5.5.14

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 utf8 */;

--
-- Database: `graveyard`
--

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

--
-- Table structure for table `admin`
--

CREATE TABLE IF NOT EXISTS `admin` (
  `adminId` int(11) NOT NULL auto_increment,
  `userName` varchar(50) NOT NULL,
  `password` varchar(50) NOT NULL
) ENGINE=MyISAM  DEFAULT CHARSET=latin1;

--
-- Dumping data for table `admin`
--

INSERT INTO `admin` (`adminId`, `userName`, `password`) VALUES
(1, 'wardens', 'Bega&1120');

在查看了各种问题后,我将其修改为

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 utf8 */;

--
-- Database: `terrier`
--

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

--
-- Table structure for table `admin`
--

CREATE TABLE IF NOT EXISTS `terrier`.`admin` (
  `adminId` int(11) NOT NULL auto_increment,
  `userName` varchar(50) NOT NULL,
  `password` varchar(50) NOT NULL
  PRIMARY KEY (`adminId`))

--
-- Dumping data for table admin
--

INSERT INTO admin (`adminId`, `userName`, `password`) VALUES
(1, 'wardens', 'Bega&1120');

这与 INSERT INTO 命令一样,但抛出错误

This gets as far as the INSERT INTO command but throws up error

#1064 - 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 '(`adminId`))


--
-- Dumping data for table admin
--

INSERT INTO admin (' at line 15 

我怀疑这是由于 MySQL 版本不同导致的问题 - 或者更有可能是我的 newby 状态.

I suspect this is a problem due to different MySQL versions - or more likely my newby status.

推荐答案

UPDATEOP 出现语法错误的原因是因为在密码列的声明后遗漏了一个逗号:

UPDATE The reason the OP is getting a syntax error is because a comma was left out following the declaration of the password column:

CREATE TABLE IF NOT EXISTS `terrier`.`admin` (
  `adminId` int(11) NOT NULL auto_increment,
  `userName` varchar(50) NOT NULL,
  `password` varchar(50) NOT NULL <-- should be a comma here
  PRIMARY KEY (`adminId`))

关于插入自动增量字段的注意事项

您正在尝试插入自动递增字段 adminId.不要为此指定值,MySQL 会自动处理.

You're trying to insert into an auto-incrementing field adminId. Don't specify a value for that, MySQL automatically takes care of it.

INSERT INTO admin (`userName`, `password`) VALUES ('wardens', 'Bega&1120');

如果你想在你的 INSERT 查询中显式地放置一个值来自动递增字段,你有三个选择,基于将字段指定为 NOT NULL- ''0NULL.这里是参考..

If you want to explicitly place a value in your INSERT queries for the auto-increment field you have three choices based on specifying the field to be NOT NULL- '', 0, or NULL. Here is the reference..

INSERT INTO admin (`adminId`, `userName`, `password`) VALUES ('', 'wardens', 'Bega&1120');
INSERT INTO admin (`adminId`, `userName`, `password`) VALUES (0, 'wardens', 'Bega&1120');
INSERT INTO admin (`adminId`, `userName`, `password`) VALUES (NULL, 'wardens', 'Bega&1120');

UPDATE 进一步测试(如@eggyal 所建议的)表明,任何 值都可以插入到自动递增字段中,而不管指定的数据库引擎如何.

UPDATE Further testing (as suggested by @eggyal) reveals that any value can be inserted into auto-increment fields regardless of the database engine specified.

这篇关于#1064 插入错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆