SELECT MySQL using Sql Developer - mysql

I managed to connect to MySQL DB via Sql Developer following this guide. MySQL DB shows and I can expolre tables via the navigator. However, I could not run SELECT statement to show any of these tables. In MySQL workbench I used to use :
use [database_name]
Then, run select statement in that database. But in Sql developer, I am not sure what should I add to the statement to make it work. I have tried the following:
select *
from [table_name].[database_name];
It does not work. I found this tutorial, but nothing is mentioned about simple select statement. Any help is deeply appreciated.

AFAIK, except MySQL specific commands; all other standard SQL commands like SELECT,INSERT,UPDATE,DELETE should work just fine using SQL Developer. but per your posted query, it looks total strange.
Your query
select * from [table_name]#[database_name];
remove that # sign.
you should qualify like database_name.table_name.
Unless it's a typo, remove those [] as well from your query
statement.
Your query should look like
select * from database_name.table_name;

You can always write your SQL including database as well, in the form of:
database.tablename
such as:
select * from wordpressdb.usertable where username="someone"

Related

USE statemet does not work in phpMyAdmin

I use SQL tab in phpMyAdmin to test statements, but some queries does not work, like, USE query; But, for example, after running USE statement and then using USE DATABASE() to check, null value returned.
USE dbname;
USE dbname
USE `dbname`;
I want to be able to run SQL statements on specific database; and this is possible after selecting (after using USE statement) database. I can click on the database name on the left sidebar and then run SQL statements, I know; But why is not possible to use "USE" statement to select database directly?
The USE statement doesn't return anything. This is why you are seeing null. It is functioning correctly.
USE sets the connection to use the database in the statement for future statements.

No database selected. MySQL Query Browser

I am using MySQL Query Browser 1.2.17. My problem is that using EXACTLY the same query sometimes I get No database selected error.
I tried to find any dependence in using USE database; or FROM database.table.
I have no idea when will I get an error and when I won't and if I get I don't know how to solve this (since there is in the query USE database;).
UPDATE AND SOLUTION:
Since the problem was independent neither on the USE database; nor FROM database.table and has been observed RANDOMLY (ex. run query, it works, then immediately run again with the same query and it didn't work anymore), I recreated the database simply filling it with data from backup and it helped.
Best practice to write query.
databasename.tablename
example
SELECT * FROM database.table where 1 = 1

Is it important to write database name before table name?

I have a database named DELTASTORE in mysql in my cpanel. There are tables like ADMIN,CATAGORY,PRODUCT,ORDER. I have inserted some values in each table.
If I run sql
SELECT * FROM ADMIN
it works nicely.
But if I run sql
SELECT * FROM ORDER
it doesn't work! Instead of that, if I run sql
SELECT * FROM DELTASTORE.ORDER
then it works correctly.
Why does that occur?
Is it important to write database name before table name and give a dot between them all the time?
To leave out the database prefix, you have to set a default database, with
USE databasename
When writing programs to access the database, the API provides a way to do this. For instance, in PHP PDO you specify the default database in the DSN:
mysql:host=hostname;dbname=defaultDB
In MySQLi it's an argument to mysqli_connect(). In the obsolete mysql extension you use mysql_use_database(). There are similar methods in other programming languages.
Additionally, since ORDER is a MySQL keyword, you either have to put it in backticks:
SELECT * FROM `ORDER`
or prefix it with a database:
SELECT * FROM DELTASTORE.ORDER
It's usually best to avoid using MySQL reserved words as table or column names, to prevent problems like this. See Syntax error due to using a reserved word as a table or column name in MySQL
The reason is, that ORDER is a SQL keyword (for ORDER BY, which you use to sort the result lines). So with the database name (or schematic name) you mean the table ORDER.
It's better to not use keywords for the table.
Just need to put brackets.
Select * from `ORDER`

Conditional/Executable Comments in MySQL/SQL Server

Before I begin, I realize that what I'm attempting is bizarre and hackish. It's just for an isolated pen test, specifically SQL Injection.
What I need to do is write a SQL statement that behaves differently when executing on a MySQL database than it does when executing on a SQL Server Database.
Edit
The limitation of the Query I can build is that I can only change what's after the "WHERE id =" clause. I can't affect any other part of the query. Specifically, I need to be able to attach a " UNION SELECT * FROM some_other_table" that only gets executed by the SQL server to the end of my input.
This obviously would blow up MySQL because it doesn't have the tables I'm unioning.
Specifically:
SELECT * FROM USERS
WHERE id = My input -> (MySQL code: 'x' or 1=1 )
(MSSQL code 'x' or 1=1 UNION SELECT * FROM table)
The problem is, if either statement gets executed by the database it wasn't meant for, it blows up (and not in the way I need it to).
This lead to my discovery of Conditional/Executable Comments in MySQL.
SELECT * FROM USERS
WHERE id = /*! This will be executed but only by mysql */
That's great but I still can't prevent MySQL from executing MSSQL! I can only stop MSSQL from executing MySQL code.
My initial idea was to have a comment inside the MySQL conditional like:
SELECT * FROM USERS
WHERE id = /*! 4 or 1=1 --*/ MSSQL code that is ignored by mysql
But this throws an error saying to check my syntax at a line with nothing on it near ''.
I don't fully understand why this doesn't work but I know doesn't work with any form of MySQL comment I know of (Tried #, /*).
Is there a way to get my strange SQL statement to work? Or is there a way to do a conditional comment in MSSQL? I really just need MySQL to ignore anything after it's conditional but I have no idea how to make that happen without comments.
I'm not sure if this is what you need, but if I understand correctly you want one SQL statement that returns different results on MySQL vs. SQL Server (if that's what "behaves differently" means?). If so, one place to start would be using a system function that has the same name and syntax but different behaviour, such as SUBSTRING():
select substring('test', -1, 1)
On SQL Server that returns an empty string, but on MySQL it returns t. I don't know if using SUBSTRING() is viable in your case, but if not you may be able to find another function that's easier to use in your query.
If this doesn't help at all then I suggest you provide some more details about what limitations you have in building your query.

How to run line by line query in mysql query browser

Suppose that I want to execute two query one is-
select * from table1;
select * from table2;
if I want to execute it I need to remove one query from two then I can execute, I'm using mysql query browser1.2.12.
If we use script tab then I can not see the output, is there any way to execute one of query from multiple query after selection.
that functionality is not available in mysql query browser on any version.
Mysql Query Browser is getting old nowdays. Mysql launch the new generation IDE with name Mysql Workbench.
use it,here u got more options.
enjoy!!
click here for workbench