Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

Original export

-- 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');

After looking at various questions I modified it to

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');

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 

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
151 views
Welcome To Ask or Share your Answers For Others

1 Answer

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`))

NOTES ON INSERTING INTO AUTO-INCREMENT FIELDS

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');

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 Further testing (as suggested by @eggyal) reveals that any value can be inserted into auto-increment fields regardless of the database engine specified.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...