In the long tradition of having hidden features, let us have a list of hidden features in MySQL.
Do put one feature per answer.
Also See:
Hidden Features of Linux
Hidden Features of PowerShell
Hidden features of Oracle Database
Hidden Features of Windows 2008
Hidden Features of Solaris/OpenSolaris
Hidden Features of SQL Server
Hidden Features of IIS (6.0 / 7.0)
An often unused but more verbose
is handy, but not as good as the awesome non-enterprise query analyser - enable like so
These two are junk queries to fill the profiles table,
Get a list of all queries profiled and their duration
Display info for last query would just be "show profile" - or you can specify a query
You can also request specific info such as CPU, BLOCK IO and SWAPS amongst others (all on man page)
Don't forget to disable it afterwards, as the logging adds overhead.
Some MySQL commands that aren't always commonly known or remembered.
Change result set orientation to vertical for easy reading and pasting.
Cancel the query you are currently typing while leaving it in your history.
Edit a query or last query (respectively) with your favourite $EDITOR.
Clear the output of the console.
Compare result sets by MD5 hash.
Change your prompt.
Search your command history for a given string (like Bash).
Start typing a search term and repeat ^R to cycle through the results.
Tricks I've learnt that may be of use to some:
To run the file you've previously saved:
Use "\!" to access shell commands. For example:
So if you wanted to write your statement to a file (without using the editor option) you could enter:
If you enter
you will then have your statements and query results directed/printed to the filemame you specified. Use
\\t
to turn this off.Terminate a query with
\\G
instead of a ";" in order to show output in a row format instead of in columns.Don't rule out using a Where...LIKE clause with the SHOW statement. For example:
Lastly, to find the location of your MySQL data directory without looking at the
my.cnf
file use:I personally like the
SHOW
commandYou could do
SHOW PROCESSLIST
- To see all the running connections to mysqlSHOW CREATE TABLE TableName
- To see the sql used to create the tableSHOW CREATE PROCEDURE ProcedureName
- To see the sql used to create the SPSHOW VARIABLES
- To see all the system variablesGet the full list here
Actually documented, but very annoying: automatic date conversions for incorrect data.
Sometimes you'll be "lucky" when MySQL doesn't adjust the input to nearby valid dates, but instead stores it as
0000-00-00
which by definition is invalid. However, even then you might have wanted MySQL to fail rather than silently storing this value for you.Another feature that sets MySQL apart from other databases is the
REPLACE INTO
command. You can do:You can also write the replace statement just like you write the update statement:
Not really a hidden feature, but it's lesser known and I use it a lot to save doing a query to check if something exists before doing an UPDATE or INSERT
Documentation is here
To see the query execution plan use
EXPLAIN
e.g.
Not really hidden, but slow-query-log can be really helpful in tracking down cause of performance problems at peak times.
In file
my.cnf
, [mysqld] section - add:Well, can't mark this as a duplicate since it's a different site (and I don't have the rep here) but I'll just link to this excellent stackoverflow post for the same question: