Skip to content
Advertisement

Import of SQL file to XAMPP error. Possible code error?

I was wondering if someone could help me. I am taking my 2nd Web Programming Classes and we’re working with MySQL. The teacher provided code to use to create the SQL database. I copy and pasted the code as he directed and proceeded to import it into XAMPP. However, when I do, I get this errorSQLImportError

I am at a loss on what to do. The Teacher has been completely and utterly unhelpful (he said he does not see what the issue is) Can anyone help me find the problem.

I have included the code. Thank you to anyone that can help

DROP DATABASE IF EXISTS my_guitar_shop1;
CREATE DATABASE my_guitar_shop1;
USE my_guitar_shop1;  -- MySQL command

CREATE TABLE categories (  
     categoryID       INT(11)        NOT NULL   AUTO_INCREMENT,  
     categoryName     VARCHAR(255)   NOT NULL,  
     PRIMARY KEY (categoryID)
     );

CREATE TABLE products (  
     productID        INT(11)        NOT NULL   AUTO_INCREMENT,  
     categoryID       INT(11)        NOT NULL,  
     productCode      VARCHAR(10)    NOT NULL   UNIQUE,  
     productName      VARCHAR(255)   NOT NULL,  
     listPrice        DECIMAL(10,2)  NOT NULL,  PRIMARY KEY (productID)
     );

CREATE TABLE orders (  
     orderID        INT(11)        NOT NULL   AUTO_INCREMENT,  
     customerID     INT            NOT NULL,  
     orderDate      DATETIME       NOT NULL,  PRIMARY KEY (orderID)
     );

INSERT INTO categories VALUES
(1, 'Guitars’),
(2, 'Basses’),
(3, 'Drums’);

INSERT INTO products VALUES
(1, 1, 'strat', 'Fender Stratocaster', '699.00’),
(2, 1, 'les_paul', 'Gibson Les Paul', '1199.00’),
(3, 1, 'sg', 'Gibson SG', '2517.00’),
(4, 1, 'fg700s', 'Yamaha FG700S', '489.99’),
(5, 1, 'washburn', 'Washburn D10S', '299.00’),
(6, 1, 'rodriguez', 'Rodriguez Caballero 11', '415.00’),
(7, 2, 'precision', 'Fender Precision', '799.99’),
(8, 2, 'hofner', 'Hofner Icon', '499.99’),
(9, 3, 'ludwig', 'Ludwig 5-piece Drum Set with Cymbals', '699.99’),
(10, 3, 'tama', 'Tama 5-Piece Drum Set with Cymbals', '799.99');

GRANT SELECT, INSERT, DELETE, UPDATE
ON my_guitar_shop1.*
TO mgs_user@localhost
IDENTIFIED BY 'pa55word’;

GRANT SELECT
ON products
TO mgs_tester@localhost
IDENTIFIED BY 'pa55word';

Advertisement

Answer

It seems you (or your teacher) copied this into Word or a similar word processor at some point. Never do that with code! That’s because word processors often “helpfully” change your text in some ways, for example by replacing simple quotes like ' with typographically better ones like . Note that ' and are different characters though! That’s nice for text written for humans, but not so nice for text written for computers which expect one very specific character and not a visually similar yet different one.

This is what happened here too. Look at this statement for example:

INSERT INTO categories VALUES
(1, 'Guitars’),
(2, 'Basses’),
(3, 'Drums’);

Do you notice it? The closing quote is always a wrong one!

enter image description here

Bottom line, never copy code into a word processor. Instead, use a regular editor, like Notepad++ or whatever IDE you are using to write your code.

To fix your immediate issue, ask your teacher for the correct code again (assuming it wasn’t your teacher who messed up the quotes in the first place!), or paste the messed-up version into your editor (not word processor) and do a search & replace, replacing all occurrences of by '.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement