Why do both commands as printed result in a syntax error message?

I am trying to enter data into the joke table. I have copied and pasted both commands as printed. Unfortunately, both commands return a syntax error message:


Error Code: 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 'joke INSERT INTO joke SET joketext = "A programmer was found dead in the shower.' at line 3 0.000 sec


Error Code: 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 'joke INSERT INTO joke SET joketext = "A programmer was found dead in the shower.' at line 3 0.000 sec


Link to content: PHP & MySQL: Novice to Ninja, 7th Edition - Section 3

Without looking at the book, should the query really begin with the word “joke”?
That doesn’t seem right. It should probably begin with “INSERT”.

4 Likes

From the manual:

So, to add a joke to our table, we can use either of these commands:

Copy

INSERT INTO joke SET
joketext = "A programmer was found dead in the shower. The instructions read: lather, rinse, repeat.",
jokedate = "2021-10-29"

// or Copy
INSERT INTO joke
(joketext, jokedate) VALUES (
"A programmer was found dead in the shower. The instructions read: lather, rinse, repeat.",
"2021-10-29")

1 Like

Thanks for your response. Unfortunately, neither of your strings work; there is no Action Output, but at least this time there is no syntax error message.

I note that both today and yesterday, when I first reported the problem, Docker appears not to be connecting:

'Error response from Daemon: Ports are not available: listen to tcp 0.0.0.0.3306: blind: Only one usage of each socket address (protocol/network address/port) is normally permitted."

I’m not doing anything differently to what I was doing with Docker before I reached this point so I am mystified as to what the problem is. Any advice is much appreciated.

This is saying that the port 3306 is already in use by something. In the output from docker do you see errors saying mysql is unable to connect?

When you started docker today what command did you use to start it?

Thanks for your quick reply.

When you started docker today what command did you use to start it?

I used ‘docker compose up’. This is what I normally use without problem. I also tried ‘docker compose start’ with the same result.

It seems that this (connection) problem with docker began only after I installed and configured MySQL. Everything was fine and dandy with Docker up to that point.

I suspect that I may have installed/configured MySQL incorrectly, so wonder if uninstalling MySQL and installing it again would be worth a try?

I’m not sure if author @TomB is around, but he might be able to help out here. I don’t think you should need to install MariaDB yourself, as it is installed in the Docker environemnt you dowloaded in Chapter 1 (but I’m no expert on these things!)

Yes, it’s included in the .yml file seen in this article, set up for port 3306.

Hi Philip,

If you have installed MySQL instead of or alongside MySQL Workbench, the default configuration probably has it run in startup unless you chose otherwise during the installation.

MySQL is the database server, and MySQL Workbench is the client. The docker image provided already includes MySQL server. So if you install and run MySQL directly on your computer then the version that runs in Docker will try to run on the same port and fail because the MySQL installation on your computer is already running.

The simple solution is to stop the MySQL service running on startup on your computer so that the port is free for the version you run in Docker.

You don’t need MySQL installed on your computer directly, only MySQL Workbench, MySQL (or more accurately, MariaDB) is provided as a docker image.

3 Likes

Thank you all for your support. I had downloaded and installed a suite of MySQL apps, only one of which was MySQL Workbench, and it appears that other apps were running as TomB suggested. I uninstalled them all except MySQL Workbench.

I have just now successfully inserted the first of the jokes into the joke database and can continue with the process of working through the Novice to Ninja coursebook.

Much appreciation.

2 Likes

OK, I spoke too soon. I was not able to add the first joke to the database after all. (The fact that even just something appeared in the Action Output made me think I had had success.)

The error message that I am receiving now is:

Error Code: 1364. Field ‘id’ doesn’t have a default value 0.000 sec

Here’s a screen shot to give you a clearer idea:

Thanks again in anticipation.

I think you need to check “AI” for the ID column.

1 Like

Take a look at the table outlined in the book: https://www.sitepoint.com/premium/books/php-mysql-novice-to-ninja-7th-edition/read/3/kye1h33j/?fromShare=true

You have skipped the step that sets up the column types and explains auto increment.

1 Like

Thanks again Tom. I’ll go back and make sure I check AI.

Thanks a lot Sam. I’ll do that right away.