Database context change - mysql

Pardon my noob question but was wondering how to change the database context within mysql? I know in SQL Server, it's:
USE [DBName];
so is there an equivalent in mysql?

In MySQL, if you want to change databases, you will also use use:
mysql> use DNNAME;

Same thing: use [database]; (the ; is optional here)
MySQL 5.0 Reference Manual :: 13.8.4 USE Syntax

The use command switches databases in MySQL. The following line
`use [database];`
will switch between databases, where you substitute the actual name of your database for [database], like use db1;.

Related

console use db use error

I am working in the mysql console and trying to use a db that has a naming convention that is so: xxx-xxxx. When I try to use the db I get an error and it seems to be that the "-" is the cause of the issue. I run mysql use xxx-xxxx and get the error. How would I overcome this so I can use the db?
You can quote mysql names (tables, columns, databases) with backticks.
So the query
use `xxx-xxxx`;
should work for you.

MySQL Basics: query execution and case sensitive

I am a newbie to mysql and having some questions on it,
Is there any way to find the execution time of any SQL statement in 'ms' approximation using command prompt (any setting to be done pls specify).
how to make your mysql to allow the case sensitive property (I have to create tables with caps on but after i created, it show the name only in small letters).
You can use EXPLAIN statements to check the execution times.
You can use lower_case_table_names system variable. Use lower_case_table_names=0 on Unix and lower_case_table_names=2 on Windows. However, if you use these settings, make sure you always use the correct case in all your MySQL queries and it can cause issues if you are switching systems from UNIX to WINDOWS or vice versa.
For 2ns you can also check collation. Some details can be found here http://dev.mysql.com/doc/refman/5.0/en/case-sensitivity.html
Check the documentation for more details.

How to determine which database is selected

Is there any way to later output the name of the database that is currently selected?
Just use mysql_query (or mysqli_query, even better, or use PDO, best of all) with:
SELECT DATABASE();
Addendum:
There is much discussion over whether or not FROM DUAL should be included in this or not. On a technical level, it is a holdover from Oracle and can safely be removed. If you are inclined, you can use it as follows:
SELECT DATABASE() FROM DUAL;
That said, it is perhaps important to note, that while FROM DUAL does not actually do anything, it is valid MySQL syntax. From a strict perspective, including braces in a single line conditional in JavaScript also does not do anything, but it is still a valid practice.
SELECT DATABASE();
p.s. I didn't want to take the liberty of modifying #cwallenpoole's answer to reflect the fact that this is a MySQL question and not an Oracle question and doesn't need DUAL.
You can always use STATUS command to get to know Current database & Current User
slightly off-topic (using the CLI instead of PHP), but still worth knowing:
You can set the prompt to display the default database by using any of the following
mysql --prompt='\d> '
export MYSQL_PS1='\d> '
or once inside
prompt \d>\_
\R \d>\_
Another way for filtering the database with specific word.
SHOW DATABASES WHERE `Database` LIKE '<yourDatabasePrefixHere>%'
or
SHOW DATABASES LIKE '<yourDatabasePrefixHere>%';
Example:
SHOW DATABASES WHERE `Database` LIKE 'foobar%'
foobar_animal
foobar_humans_gender
foobar_objects

MySQL CHECK constraint alternative

As per the MySQL manual "The CHECK clause is parsed but ignored by all storage engines." So I know the simple solution is out of the question but is there another feasible means of coming to the same outcome? Maybe through some use of triggers or stored procedures? If so how?
Also since it is just "parsed" is that as good as saying avoid using it since it doesn't serve a purpose?
Using MySQL 5.5.11 and InnoDB tables
Take a look at this interesting article
https://wikis.oracle.com/display/mysql/Triggers#Triggers-EmulatingCheckConstraints
I often use that method.
I am using version 5.5.21
you can use ENUM for check constraints
http://dev.mysql.com/doc/refman/5.0/en/enum.html

what is the non-standard words&usage in mysql

I'm using mysql for a while. I think to switch pdo, and want to use standard function. Can you provide non-standard syntax in mysql?
First think LIMIT in oracle they use rowcount, and mssql they use TOP .
Is this the question you are looking for:
There are a method to paging using ANSI SQL only?