How to make a field NULL using MySQL GUI Tools? - mysql

I'm using the MySQL Query Browser (part of the MySQL GUI Tools) and need to change a field to NULL, but I can't figure out how to do it - if I delete the value it tries to update it to ''. Typing "NULL" makes it try to update to 'NULL' (a string).
I know I could just write a query to do it, but that defeats the entire purpose of the tool, no?

In MySQL Query Browser, right click on the cell and select 'Clear field content' while the focus is in another cell.
In MySQL Workbench, right click on the cell and select 'Set Field to NULL'.

In MySQL Workbench, with the cell selected, press Shift + Delete
Tested on 6.3.4.0

Right-click on that column and select the
'Set field to Null'
option from the context menu.

Removing the contents:
This works for some tools (sorry to hear it doesn't for yours).
This may not appear as null but will when you perform a query.

Shift + Delete
work well in MySql Workbench 8

I'd try Ctrl-0 (zero), because that works in some tools.

Related

How do you execute a query in Sequel Pro?

I want to execute a query in a MySQL DB using Sequel Pro, but I do not see a Run button.
How do I execute my query?
Use ⌘+R to execute the selected Query.
Alternatively, use the dropdown that appears at the bottom right of the query editor and select Run Current or Run Previous depending on where your text cursor is.
Based on Keyboard Shortcuts:
Run all queries ⌥ ⌘ R
Run current query or selection ⌅ or ⌘ R
Use the drop down button on the right side, underneath the textarea.
Should have the following options:
Run Current Query
Run All Queries
Came here to find ⌘ + return to execute a query (like MySQL Workbench).
Found that I can map using mac Key bindings with the names of Run Current Query and Run Previous Query.
If you want to do it via terminal it would be (untested):
defaults write com.sequelpro.SequelPro NSUserKeyEquivalents '{
"Run Current Query" = "#\\U21a9";
"Run Previous Query" = "#\\U21a9";
}'
Note: you may have to restart the app.

MySQL Workbench - How do I set a value to NULL using the GUI? [duplicate]

I'm using the MySQL Query Browser (part of the MySQL GUI Tools) and need to change a field to NULL, but I can't figure out how to do it - if I delete the value it tries to update it to ''. Typing "NULL" makes it try to update to 'NULL' (a string).
I know I could just write a query to do it, but that defeats the entire purpose of the tool, no?
In MySQL Query Browser, right click on the cell and select 'Clear field content' while the focus is in another cell.
In MySQL Workbench, right click on the cell and select 'Set Field to NULL'.
In MySQL Workbench, with the cell selected, press Shift + Delete
Tested on 6.3.4.0
Right-click on that column and select the
'Set field to Null'
option from the context menu.
Removing the contents:
This works for some tools (sorry to hear it doesn't for yours).
This may not appear as null but will when you perform a query.
Shift + Delete
work well in MySql Workbench 8
I'd try Ctrl-0 (zero), because that works in some tools.

phpMyAdmin - how to save a SPATIAL Point

I'm trying to store a Spatial Point in a dataBase in phpMyAdmin and I don't know why is always shown like [GEOMETRY-25B]. Below is the command I use.
INSERT INTO `locations`(`Location`) VALUES (GeomFromText( 'POINT(40 -100)'))
or
INSERT INTO `locations`(`Location`) VALUES (Point(40,-100))
Click on Options, then select "Full text" and "Well Known Text".
I found something. The points are stored ok and if you try to execute the query below it returns the points as POINT(4 5) for example. But how can I make them visible to the table?
SELECT AsText(`Location`) FROM `products`
Update:
As #Marc mentioned above, after the upgrade of phpMyAdmin to the latest version 4.0.7 there is an Option "Well Known Text" which makes points visible to the table.

Pasting SQL into the MySQL command line

I have an application that is defining some SQL code:
mySql = "SELECT
sq.question,
qs.title,
sq.id as question_id,
sq.type,
qs.id as option_id,
sri.title as rankTitle,
sri.id as rankId,
sfi.title as formTitle,
sfi.id as formId,
sq.sub_type,
sq.sort_order
FROM survey_questions as sq
LEFT JOIN question_suboptions as qs
ON sq.id = qs.question_id
LEFT JOIN survey_rankingitems as sri
ON sq.id = sri.question_id
LEFT JOIN survey_formitems as sfi
ON sq.id = sfi.question_id
WHERE sq.survey_id = #{#surveyId}
ORDER BY sq.sort_order"
I would like to paste this code (everything between the double quotes) in the MySQL command line, change the one parameter and execute it, but I have run into an issue where for every line above MySQL will display:
Display all 1450 possibilities? (y or n)
And then 1450 different available commands. If I remove all linebreaks and tabs then I can paste in, but that is time consuming and a pain. Is there a way that I can simply paste in the above code, edit it and then execute it as a single unit?
This is the default mysql (CLI) behavior each time the user presses the Tab key (mysql uses the underlying readline or EditLine libraries (not on Windows)).
By default, when the user requests to use a database, mysql reads tables and fields definitions. Then, pressing the Tab key makes mysql conveniently offers completion of the current input with the known tables and fields.
However, pasting some text into mysql that contains TAB characters (\t or 0x09) triggers the same behavior - even though no Tab key was actually pressed from the keyboard. And this can be annoying.
Two options given to mysql can prevent that behavior, though. My favorite is --disable-auto-rehash. The other one is --quiet or -q.
--disable-auto-rehash to prevent database, table, and column name completion (which are not read from the database, use the rehash command if later on you need completion). Commands history is kept, though (retrieved via the ↑ and ↓ keys for instance). Which is convenient.
--quick or -q which makes mysql not using the history file and no completion (does not read the database definitions).
On Linux one may add an alias in .bashrc to use --disable-auto-rehash automatically
alias mysql2='mysql --disable-auto-rehash'
Perhaps you could save the statement to a text file myTest.sql, then use the MySQL command source myTest.sql to run it? You could then tweak the SQL in the file, save the changes, and run it again.
You need to remove the line breaks and tabs. The double tab is causing it to display the Display all 1450 possibilities? (y or n) and the line breaks are causing it to execute early.
If it's PHP, write a little script to strip it for you:
echo (preg_replace("/\s+/", " ", $string));
Or something similar for other languages.
Breaking not so bad's answer explained the cause of this problem really well.
From the question:
If I remove all linebreaks and tabs then I can paste in, but that is time consuming and a pain.
In my case, I just replaced the tabs with spaces and I was able to paste the query just fine. The MySQL console doesn't seem to care about the newlines, just the tabs.
As a way to prevent this, most editors have a setting that will insert tabs instead of spaces when you press the Tab key. I normally have my IDEs configured this way, but in this instance it was a query I'd copied from MySQL workbench. Conveniently, it also has a setting to use spaces instead of tabs:
Edit > Preferences > General Editors > check Tab key inserts spaces instead of tabs > OK

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