Basic MySQL User Utility Commands

USE Syntax

USE db_name

The USE db_name statement tells MySQL to use the db_name database as the default database for subsequent queries. The database remains current until the end of the session or until another USE statement is issued:

mysql> USE db1;
mysql> SELECT COUNT(*) FROM mytable;      # selects from db1.mytable
mysql> USE db2;
mysql> SELECT COUNT(*) FROM mytable;      # selects from db2.mytable

Making a particular database current by means of the USE statement does not preclude you from accessing tables in other databases. The following example accesses the author table from the db1 database and the editor table from the db2 database:

mysql> USE db1;
mysql> SELECT author_name,editor_name FROM author,db2.editor
    ->        WHERE author.editor_id = db2.editor.editor_id;

The USE statement is provided for Sybase compatibility.

DESCRIBE Syntax (Get Information About Columns)

{DESCRIBE | DESC} tbl_name {col_name | wild}

DESCRIBE is a shortcut for SHOW COLUMNS FROM. See Section 4.5.6.1.

DESCRIBE provides information about a table’s columns. col_name may be a column name or a string containing the SQL % and _ wildcard characters.

If the column types are different from what you expect them to be based on a CREATE TABLE statement, note that MySQL sometimes changes column types. See Section 6.5.3.1.

This statement is provided for Oracle compatibility.

The SHOW statement provides similar information. See Section 4.5.6.

Get MySQL Reference Manual now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.