The mysql> Prompt
Everything in this course happens at one prompt. It is worth five minutes to know exactly what you are looking at when it appears — and what to do when it changes shape on you, which it will, probably within your first ten queries.
1Opening the client
MySQL comes in two halves. The server is a program that runs quietly in the background and looks after the data. The client is what you type into. On Windows it is in the Start menu as MySQL 8.0 Command Line Client.
It asks for the password that was set when MySQL was installed. Nothing appears as you type it — not even dots in some versions. That is deliberate, not a broken keyboard. Press Enter, and if the password is right you get this:
Only the last line matters. mysql> is the MySQL prompt: the client is connected, it is waiting, and anything you type now goes to the server.
mysql> on its own line.2The semicolon runs the query
The banner told you already: Commands end with ; or \g. Pressing Enter is not what runs a query. The semicolon is.
This matters because it lets one query stretch over several lines. Here is a real session where the query is split across two of them:
After the first Enter the prompt changed from mysql> to ->. That is the continuation prompt, and it means “I am still listening; you have not finished”. The moment the semicolon arrived, the whole thing ran as one query.
; and press Enter to run it — or type \c and press Enter to throw the half-written query away and get a clean mysql> back.3Reading what comes back
Replies come in three shapes, and telling them apart is most of what “reading the screen” means here.
You asked a question and here is the answer, with a count at the bottom: 1 row in set (0.00 sec). If the question matched nothing you get Empty set instead, which is an answer, not a failure.
Query OK, 1 row affected or Database changed. There is nothing to show, so MySQL just reports what it did.
ERROR 1146 (42S02): Table 'lambdalab.student' doesn't exist. Read it: it usually names the exact thing that is wrong. Here, a missing s.
4Case and spacing do not matter
SQL keywords are not case sensitive, and neither are column names in MySQL. All of these do the same thing:
Notice the heading came back as Name — the case you typed. Many textbooks write keywords in capitals to make them stand out. This course writes them in lower case, matching the class notes. Either is accepted in an exam; just be consistent within one query.
city = "gangtok" matches a stored "Gangtok" depends on how the database was set up, so do not rely on it — type values with the same capitals they were stored with.5Leaving
exit or quit closes the client. Your data is safe — every query that changed something was carried out the moment you ran it, so there is nothing to save. What you do lose is the database you chose with use, which is why the next session starts with choosing it again.
6Recap
Connected and waiting for a query.
Still typing — no semicolon yet. \c abandons the query.
Enter alone does not. One query may span many lines.
Closes the client. Replies Bye.
You type a query, press Enter, and the prompt shows -> instead of mysql>. What should you do?
What actually causes a query to run?
Which reply means the query worked but matched no rows?