Jump to content
Larry Ullman's Book Forums

Ch 5, Pg 136 - Mysql Terminal Error 1064 (42000)


Recommended Posts

I entered in the below code into terminal and got the error below in red.  Not sure where the error is?  I double checked it but operating on minimal sleep so maybe a dumb error...

INSERT INTO users (first_name, last_name, email, pass, registration_date) VALUES    
('John', 'Lennon', 'john@beatles.com', SHA1('Happin3ss'), NOW()),
('Paul', 'McCartney', 'paul@beatles.com', SHA1('letITbe'), NOW()),
('George', 'Harrison', 'george@beatles.com', SHA1('something'), NOW()),
('Ringo', 'Starr', 'ringo@beatles.com', SHA1('thisboy'), NOW());


ERROR 1064 (42000): 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 'VALUES
('John', 'Lennon', 'john@beatles.com', SHA1('Happin3ss'), NOW()),
('Paul'' at line 1

Link to comment
Share on other sites

Sure here is all the code below.  There is an error towards the bottom (George Harrison) I did find, but, as you'll see after that I corrected it (it was missing 1 parenthesis on the NOW ).  Maybe you can find something.  Maybe restart everything??

mysql> use sitename;
Database changed
mysql> CREATE TABLE users (
    -> user_id MEDIUMINT UNSIGNED NOT NULL
    -> AUTO_INCREMENT,
    -> first_name VARCHAR(20) NOT NULL,
    -> last_name VARCHAR(40) NOT NULL,
    -> email VARCHAR(60) NOT NULL,
    -> pass CHAR(40) NOT NULL,
    -> registration_date DATETIME NOT NULL,
    -> PRIMARY KEY (user_id)
    -> );
Query OK, 0 rows affected (0.03 sec)

mysql> SHOW TABLES;
+--------------------+
| Tables_in_sitename |
+--------------------+
| users              |
+--------------------+
1 row in set (0.00 sec)

mysql> SHOW COLUMNS FROM users;
+-------------------+-----------------------+------+-----+---------+----------------+
| Field             | Type                  | Null | Key | Default | Extra          |
+-------------------+-----------------------+------+-----+---------+----------------+
| user_id           | mediumint(8) unsigned | NO   | PRI | NULL    | auto_increment |
| first_name        | varchar(20)           | NO   |     | NULL    |                |
| last_name         | varchar(40)           | NO   |     | NULL    |                |
| email             | varchar(60)           | NO   |     | NULL    |                |
| pass              | char(40)              | NO   |     | NULL    |                |
| registration_date | datetime              | NO   |     | NULL    |                |
+-------------------+-----------------------+------+-----+---------+----------------+
6 rows in set (0.01 sec)

mysql> INSERT INTO users 
    -> (first_name, last_name, email, pass, registration_date)
    -> VALUES ('John', 'smith', 'johnsmith@yahoo.com', SHA1('testpassword'), NOW());
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO users VALUES
    -> (NULL, 'Zoe', 'Isabella', 'email2@example.com', SHA1('mojito'), NOW());
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:    44
Current database: sitename

Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO users (first_name, last_name, email, pass, registration_date) VALUES
    -> ('John', 'Lennon', 'john@beatles.com', SHA1('Happin3ss'), NOW()),
    -> ('Paul', 'McCartney', 'paul@beatles.com', SHA1('lefITbe'), NOW()),
    -> ('George', 'Harrison', 'george@beatles.com', SHA1('something'), NOW(),
    -> ('Ringo', 'Starr', 'ringo@beatles.com', SHA1('thisboy'), NOW());
ERROR 1064 (42000): 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 '' at line 5
mysql> INSERT INTO users (first_name, last_name, email, pass, registration_date) VALUES    -> ('John', 'Lennon', 'john@beatles.com', SHA1('Happin3ss'), NOW()),
    -> ('Paul', 'McCartney', 'paul@beatles.com', SHA1('letITbe'), NOW()),
    -> ('George', 'Harrison', 'george@beatles.com', SHA1('something'), NOW()),
    -> ('Ringo', 'Starr', 'ringo@beatles.com', SHA1('thisboy'), NOW());
ERROR 1064 (42000): 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 'VALUES
('John', 'Lennon', 'john@beatles.com', SHA1('Happin3ss'), NOW()),
('Paul'' at line 1
mysql> INSERT INTO users (first_name, last_name, email, pass, registration_date) VALUES ('John', 'Lennon', 'john@beatles.com', SHA1('Happin3ss'), NOW()), ('Paul', 'McCartney', 'paul@beatles.com', SHAe) VALUES ('John', 'Lennon', 'john@beatles.com', SHA1('Happin3ss'), NOW()), ('Paul', 'McCartney', 'paul@beatles.com', SHA1('letITbe'), NOW()), ('George', 'Harrison', 'george@beatles.com', SHA1('something'), NOW()), ('Ringo', 'Starr', 'ringo@beatles.com', SHA1('thisboy'), NOW());
ERROR 1064 (42000): 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 'VALUES ('John', 'Lennon', 'john@beatles.com', SHA1('Happin3ss'), NOW()), ('Paul'' at line 1

Link to comment
Share on other sites

I entered in the below code into terminal and got the error below in red.  Not sure where the error is?  I double checked it but operating on minimal sleep so maybe a dumb error...

INSERT INTO users (first_name, last_name, email, pass, registration_date) VALUES    
('John', 'Lennon', 'john@beatles.com', SHA1('Happin3ss'), NOW()),
('Paul', 'McCartney', 'paul@beatles.com', SHA1('letITbe'), NOW()),
('George', 'Harrison', 'george@beatles.com', SHA1('something'), NOW()),
('Ringo', 'Starr', 'ringo@beatles.com', SHA1('thisboy'), NOW());


ERROR 1064 (42000): 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 'VALUES

('John', 'Lennon', 'john@beatles.com', SHA1('Happin3ss'), NOW()),

('Paul'' at line 1

 

I tested this code and it worked for me without changing your code.

So I'm not sure why either.

Link to comment
Share on other sites

 Share

×
×
  • Create New...