2006-12-13

MySQL hints

Here are the three most important things to get you through your MySQL day:

Invoking the mysql client: The basic syntax to invoke the client, login, and connect to a database is:

mysql -u username -p database_name

or

mysql -u username --password=yourPassword databaseName

For example:

$ mysql -u timmy --password=likesbikes bikes
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 573844 to server version: 5.0.19-standard

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

Getting the list of tables: If you don't already know the schema, you'll start by using show tables to get the list of tables:

mysql> show tables;
+---------------------------+
| Tables_in_bikes |
+---------------------------+
| foo |
| bar |
| baz |
+---------------------------+
3 rows in set (0.00 sec)

Individual table information: Finally, you'll use describe articles to find out about the names, data types, and other information about the columns in a table:

mysql> describe foo;
+--------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+----------------+
| id | bigint(20) | NO | PRI | | auto_increment |
| source_url | varchar(255) | YES | | | |
| title | varchar(255) | YES | | | |
| foo_date | date | YES | | | |
| author | varchar(255) | YES | | | |
| body | text | YES | | | |
| release_date | date | YES | | | |
| summary | text | YES | | | |
+--------------+--------------+------+-----+---------+----------------+
8 rows in set (0.00 sec)

mysql>

No comments:

LinkWithin

Related Posts with Thumbnails