Using
mysql
in Batch Mode
214
You have previously seen
SHOW DATABASES
, which lists the databases managed by the server. To
find out which database is currently selected, use the
DATABASE()
[960]
function:
mysql>
SELECT DATABASE();
+------------+
| DATABASE() |
+------------+
| menagerie |
+------------+
If you have not yet selected any database, the result is
NULL
.
To find out what tables the default database contains (for example, when you are not sure about the
name of a table), use this command:
mysql>
SHOW TABLES;
+---------------------+
| Tables_in_menagerie |
+---------------------+
| event |
| pet |
+---------------------+
The name of the column in the output produced by this statement is always
Tables_in_db_name
,
where
db_name
is the name of the database. See
Section 13.7.5.34, “
SHOW TABLES
Syntax”
, for more
information.
If you want to find out about the structure of a table, the
DESCRIBE
statement is useful; it displays
information about each of a table's columns:
mysql>
DESCRIBE pet;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| name | varchar(20) | YES | | NULL | |
| owner | varchar(20) | YES | | NULL | |
| species | varchar(20) | YES | | NULL | |
| sex | char(1) | YES | | NULL | |
| birth | date | YES | | NULL | |
| death | date | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
Field
indicates the column name,
Type
is the data type for the column,
NULL
indicates whether the
column can contain
NULL
values,
Key
indicates whether the column is indexed, and
Default
specifies
the column's default value.
Extra
displays special information about columns: If a column was created
with the
AUTO_INCREMENT
option, the value will be
auto_increment
rather than empty.
DESC
is a short form of
DESCRIBE
. See
Section 13.8.1, “
DESCRIBE
Syntax”
, for more information.
You can obtain the
CREATE TABLE
statement necessary to create an existing table using the
SHOW
CREATE TABLE
statement. See
Section 13.7.5.9, “
SHOW CREATE TABLE
Syntax”
.
If you have indexes on a table,
SHOW INDEX FROM tbl_name
produces information about them. See
Section 13.7.5.18, “
SHOW INDEX
Syntax”
, for more about this statement.
3.5. Using
mysql
in Batch Mode
In the previous sections, you used
mysql
interactively to enter queries and view the results. You can
also run
mysql
in batch mode. To do this, put the commands you want to run in a file, then tell
mysql
to read its input from the file:
shell>
mysql < batch-file
If you are running
mysql
under Windows and have some special characters in the file that cause
problems, you can do this:
Содержание 5.0
Страница 1: ...MySQL 5 0 Reference Manual ...
Страница 18: ...xviii ...
Страница 60: ...40 ...
Страница 396: ...376 ...
Страница 578: ...558 ...
Страница 636: ...616 ...
Страница 844: ...824 ...
Страница 1234: ...1214 ...
Страница 1426: ...MySQL Proxy Scripting 1406 The following diagram shows an overview of the classes exposed by MySQL Proxy ...
Страница 1427: ...MySQL Proxy Scripting 1407 ...
Страница 1734: ...1714 ...
Страница 1752: ...1732 ...
Страница 1783: ...Configuring Connector ODBC 1763 ...
Страница 1793: ...Connector ODBC Examples 1773 ...
Страница 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Страница 1842: ...Connector Net Installation 1822 5 Once the installation has been completed click Finish to exit the installer ...
Страница 1864: ...Connector Net Visual Studio Integration 1844 Figure 20 24 Debug Stepping Figure 20 25 Function Stepping 1 of 2 ...
Страница 2850: ...2830 ...
Страница 2854: ...2834 ...
Страница 2928: ...2908 ...
Страница 3000: ...2980 ...
Страница 3122: ...3102 ...
Страница 3126: ...3106 ...
Страница 3174: ...3154 ...
Страница 3232: ...3212 ...