What does getting a prompt after creating a database mean? - mysql

Everywhere I look I can't find this "EXACT" situation.
I enter: create database october24
after hitting return I get:
->
So it's not my regular linux prompt and it's not the mysql prompt after logging in, which is mysql>
I don't get/see any errors just that crappy little prompt. I have to "ctrl-c" to get out, otherwise, nothing I enter after that prompt does squat. I haven't found anything on this. Can someone who is more versed in msyql/SQL point me in the right direction?
Thanks

You need to end each statement with a semi-colon (;).
create database october24;
That prompt is because MySQL doesn't know you were done with your query and is expecting more input.

You're missing a semi-colon. Type it, press enter and then the prompt will be back :)
EG:
mysql> select id, max(name)
-> from table
-> group by id;

Related

MYSQL codes not being read

When I input a code or anything into MySQL and hit "enter" it moves down and "->" appears. It is as if the code is not going through or the code is not being read.
I have attempted to download "add-ons" but I am really not sure what I am doing. This is for school and I am having trouble getting in touch with the professor.
I am new to this and can't figure out what I am doing wrong. Please help!
Please see image of what it looks like to me.
Please add semicolon ; after the mysql code.
Problem 1: Be aware of the prompt. Either of these
MariaDB >
mysql >
means that you are inside the MySQL commandline tool. You can enter only SQL statements. Most SQL queries need to be terminated by a ; or \G (but not both). To exit that tool:
exit
Or, if you get stuck in certain ways
CTRL-C
exit
Each of these implies a shell script:
$
#
mymachine$
/usr/home/rj $
C:\Users\rj:
and many others
Problem 2: mysqldump is a command, not SQL. So it needs to be executed in a shell script.
Problem 3: There is yet another problem. When it suggested typing 'help;', it did not mean for you to include the quotes. Instead, type just help;.

Pass parameter from Batch file to MYSQL script

I'm having a really hard time believing this question has never been asked before, it MUST be! I'm working on a batch file that needs to run some sql commands. All tutorials explaining this DO NOT WORK (referring to this link:Pass parameters to sql script that someone will undoubtedly mention)! I've tried other posts on this site verbatim and still nothing is working.
The way I see it, there are two ways I can approach this:
1. Either figure out how to call my basic MYSQL script and specify a parameter or..
2. Find an equivalent "USE ;" command that works in batch
My Batch file so far:
:START
#ECHO off
:Set_User
set usrCode = 0
mysql -u root SET #usrCode = '0'; \. caller.sql
Simply put, I want to pass 'usrCode' to my MYSQL script 'caller.sql' which looks like this:
USE `my_db`;
CALL collect_mismatch(#usrCode);
I know that procedures are a whole other topic to get into, but assume that the procedure is working just fine. I just can't get my parameter from Batch to MYSQL.
Ideally I would like to have the 'USE' & 'CALL' commands in my Batch file, but I can't find anything that let's me select a database in Batch before CALLing my procedure. That's when I tried the above link which boasts a simple command line entry and you're off to the races, but it isn't the case.
Any help would be greatly appreciated.
This will work;
echo SET #usrCode = '0'; > params.sql
type params.sql caller.sql | mysql -u root dbname

How do you clear an unexecuted MySQL query from the command line?

Suppose you're typing a command line query into a MySQL database and you need to cancel out and start over. From a bash shell you could just type ctrl-c and get a new prompt. In MySQL, ctrl-c would exit the client and return you to the shell.
For example, I have a long, complex SELECT statement typed in but I haven't yet hit return. I realize that I don't want to send the command but I want to have the command on-screen so I can use it as a reference. I'd like to bail out without quitting MySQL. Any ideas?
Key point: the command hasn't yet been executed.
Type \c.
When you start up MySQL, you'll likely see this message:
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
The "buffer" that it's referring to is the command/query buffer.
First type Ctrl+a, then Ctrl+k.
Use one of the following shortcuts to delete the current line:
Type Ctrl + u to delete everything from the cursor back to the line start
Type Ctrl + k to delete everything from the cursor to the end of the line
Otherwise as already indicated type \c at the end of the current line (a shortcut for the clear command) and then press Enter.
In mysql 5.7, this has been resolved. You can now do ctrl-c to exit the SQL command line.
If it's a long command I usually arrow to the beginning of the command and add gibberish, so it won't execute, but I can up-arrow and gain access without having to re-type it. Otherwise if you want to not execute it, just hit the up-arrow and it should scroll you through your command history. Find a short command, backspace, then type whatever you want.
Depends on your shell's key bindings. You could press home or what ever key sequence you use to get back to the start, prefix your query with X or what ever to make it syntactically invalid, hit enter and you're good
If you came here hoping to find the same answer in Transact-SQL, type RESET

Problem with mysql console

When i login in to my mysql account i doing something like this:
mysql>TRUNCATE MyTable
->
->
->
but there is no response informations but only more -> with every pressed Enter. It is right that there is only more -> and nothing else with every pressed Enter?
For more i can see on my mysql based page that data which i want to remove is still existing. It is normal?
You need to terminate the statement with a semicolon ;
mysql>TRUNCATE MyTable;

Executing Line/Multiple Lines Only in mySQL Query Browser

I already used Microsoft SQL Server 2005 and found really easy to execute single/multiple lines of an sql query.
Example:
insert into tablea
($vala, $valb, $valc)
values
($vala, $valb, $valc);
insert into tableb
($vala, $valb, $valc)
values
($vala, $valb, $valc);
How can I execute the second part only? In MSSQL i will highlight the second insert statment and press F5. How can do this in mySQL?
The problem is that you must be trying to execute your query from a Query Tab rather than from a Script Tab. Go to File -> New Script Tab and input your multiple statements there. Next click the execute button... that's it.
Hope it helps!
Machi
You can do this. When you have logged into MySQL query browser, and you write two complete statments such as:
select "hello world";
select "second query";
You will notice two blue dots on the left side of the window they are left of the line numbers. By default it will try to exec the first command. That might be why you see one command with white background and all the others with a grey background. The command that is white, is highlighted and it is the one that will be executed. You should be able to just click anywhere inside the second query to highlight it and then click the lightning bolt button (execute) to run it.
You can do this in MySQL, but you have to use mysqli. Click here for details:
http://php.net/manual/en/mysqli.quickstart.multiple-statement.php
In workbench, make sure the cursor is in the statement you want to execute and hit Ctrl+Enter.
Ctrl+Shift+Enter will run all statements consecutively in the window/document.
In addition if you have selected a statement, Ctrl+Shift+Enter will execute the selected statement only.
Does selecting the second part and "EXECUTE" help? If not, then I am not sure if such a use case is supported. You might want to try MySQL Workbench though.
well the issue here is that if i write the queries :
select "hello world";
select "second query";
and Execute it gives error -- when i select/highlight any one of them and execute it gives the same error -- so i have to either delete one of the queries or comment it out or use the script editor which doesn't work for me and lot of other users who have use MS SQL 2000,2005.
If there a solution for this -- ideally it should execute the query i select .
Just an opinion
Rohan