Home >> FAQs/Tutorials >> MySQL Tutorials

MySQL FAQs - Command-Line End User Interface mysql

By: FYIcenter.com

Part:   1  2   3  4 

(Continued from previous part...)

What Are the "mysql" Command Line Arguments?

"mysql" supports only one optional command line argument, "database". But "mysql" allows the operating system to redirect input and output streams at the command line level. Here are some good examples:

  • "mysql databaseName" - Starts "mysql" in interactive mode and use the specified database.
  • "mysql < fileName" - Starts "mysql" in batch mode and executes all commands in the specified file.
  • "mysql < fileName > fileName" - Starts "mysql" in batch mode, executes all commands in the specified file, and write output to the specified file.

Here is a tutorial exercise of how to use the command line argument to specify the database to use:

>cd \mysql\bin
>mysql -u root test
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4 to server version: 5.0.24

mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| links          |
+----------------+
1 row in set (0.00 sec)

mysql> quit;
Bye

How Many SQL DDL Commands Are Supported by "mysql"?

There are 4 SQL Data Definition Language (DDL) commands that are supported by "mysql". They are listed below with short descriptions:

  • "CREATE dataObjectType dataObjectName" - Creates new databases, tables, views, triggers, indexes, and other data objects.
  • "RENAME dataObjectType dataObjectName" - Renames existing databases, tables, views, triggers, indexes, and other data objects.
  • "ALTER dataObjectType dataObjectName" - Alters properties of existing databases, tables, views, triggers, indexes, and other data objects.
  • "DROP dataObjectType dataObjectName" - Drops existing databases, tables, views, triggers, indexes, and other data objects.

Here is a tutorial exercise of how to use DDL commands to create a database and a table:

>cd \mysql\bin
>mysql -u root

mysql> CREATE DATABASE fyi;
Query OK, 1 row affected (0.50 sec)

mysql> CREATE TABLE articles (name VARCHAR(80));
Query OK, 0 rows affected (0.25 sec)

mysql> DROP DATABASE fyi;
Query OK, 0 rows affected (0.41 sec)

How Many SQL DML Commands Are Supported by "mysql"?

There are 4 SQL Data Manipulation Language (DML) commands that are supported by "mysql". They are listed below with short descriptions:

  • "INSERT INTO tableName ..." - Inserts new data rows into the specified table.
  • "DELETE FROM tableName ..." - Deletes existing data rows from the specified table.
  • "UPDATE tableName SET ..." - Updates existing data rows in the specified table.
  • "SELECT expressionList FROM ..." - Selects rows from tables and returns rows of values resulted from the specified expression list.

Here is a tutorial exercise of how to use DML commands to insert and select data rows:

>cd \mysql\bin
>mysql -u root test

mysql> CREATE TABLE links (id INTEGER, name VARCHAR(80));
Query OK, 0 rows affected (0.10 sec)

mysql> INSERT INTO links VALUES (1, 'dba.fyicenter.com');
Query OK, 1 row affected (0.02 sec)

mysql> SELECT * FROM links;
+------+-------------------+
| id   | name              |
+------+-------------------+
|    1 | dba.fyicenter.com |
+------+-------------------+
1 row in set (0.04 sec)

(Continued on next part...)

Part:   1  2   3  4 

MySQL Tutorials:

More...


Other Tutorials/FAQs:

More...


Related Resources:

More...


Selected Jobs:

More...