MySQL Prompt Commands

From the MySQL prompt, you can do more than just query data. In fact, to query data, you need to tell MySQL which database to use first. To see what databases are available, you can ask MySQL to show you the databases.

show databases; 

This should yield something like:

mysql> show databases; +-----------+ | Database  | +-----------+ | PerlBook | | mysql     | | test      | +-----------+     3 rows in set (0.00 sec)

The database named test is what MySQL uses to run its tests when it is installed. The database named mysql is where MySQL stores all of its access information, such as user permissions.

The PerlBook database is the one we are using for this book. To use a database, just type use databasename; as in the following example:

use PerlBook;

MySQL should return a message telling you that the database has changed. At this point, you can have MySQL show you the available tables in the same manner that you ask it to show you the databases.

show tables;

One other command you may find useful at the mysql> prompt is describe. It displays a description of the table you ask for. For example,

describe library;

results in something like this being displayed:

mysql> describe library; +-----------+--------------+------+-----+---------+-------+ | Field     | Type         | Null | Key | Default | Extra | +-----------+--------------+------+-----+---------+-------+ | isbn      | varchar(20)  | YES  |     | NULL    |       | | title     | varchar(255) | YES  |     | NULL    |       | | author    | varchar(255) | YES  |     | NULL    |       | | price     | varchar(20)  | YES  |     | NULL    |       | | format    | varchar(50)  | YES  |     | NULL    |       | | publisher | varchar(255) | YES  |     | NULL    |       | | pubdate   | varchar(50)  | YES  |     | NULL    |       | | notes     | text         | YES  |     | NULL    |       | +-----------+--------------+------+-----+---------+-------+ 8 rows in set (0.00 sec) 

Other commands are available from the mysql> prompt, but they are not as widely used, so they aren’t covered here. Make sure you take a look at the latest MySQL documentation to get an in-depth description of these commands as well as the ones we did not cover.



Perl Database Programming
Perl Database Programming
ISBN: 0764549561
EAN: 2147483647
Year: 2001
Pages: 175

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net