MYSQL Command line Client commands series

Source: Internet
Author: User
Tags mysql command line

——————————————————————————————————————————————————————————

First, start and exit

1. Go to MySQL: start MySQL Command line Client (MySQL dos interface) and enter the installation password directly. At this point the prompt is:mysql>

2. Exit MySQL: quitOr Exit


Second, the library operation

1. Create a database

Command: CREATE DATABASE

For example, create a database named XHKDB

mysql> CREATE DATABASE xhkdb;


2. Show all databases

Command: Show Databases(Note: There is a last s)

mysql> show databases;


3. Delete Database

Command: DROP Database

Example: Delete a database named Xhkdb

mysql> drop Database xhkdb;


4. Connect to the database

Command: Use

For example: If the XHKDB database exists, try to access it:

mysql> use XHKDB;

Screen tip: Database changed


5, the current selection (connection) of the database

Mysql> Select Database ();


6. The current database contains table information:

Mysql> show tables;(Note: There is a last s)


Third, table operation, should connect a database before operation

1. Build a table

Command: CREATE TABLE( [,.. ]);

mysql> CREATE TABLE ' Testa ' (
' id ' int (ten) UNSIGNED not NULL auto_increment,
' Name ' varchar (), DEFAULT NULL,
-PRIMARY KEY (' id ')
) Engine=myisam auto_increment=65 DEFAULT Charset=utf8;


2. Get the table structure

Command: descTable name, or Show columns from table name

Mysql> DESCRIBE MyClass

mysql> desc MyClass;

Mysql> show columns from MyClass;


3. Delete a table

Command: drop table

Example: Deleting a table with a table named MyClass

mysql> drop table MyClass;


4. Inserting data

Command: Insert into[( [,.. ])] Values (value 1) [, (value N)]


5. Querying the data in the table

1), Query all rows

Mysql> Select* FROM MyClass;


2), query the first few rows of data

Mysql> Select* FROM MyClass ORDER by ID Limit0,2;


6. Delete data from the table

Command: DeleteFrom table name where expression

Example: Deleting a record with number 1 in table MyClass

Mysql> Delete from MyClass where id=1;


7. Modify the data in the table: Update table name SET field = new value,... WHERE condition

Mysql> UpdateMyClass set name= "Mary" where id=1;


8. Add a field to the table:

Command: ALTER TABLETable name add field type other;

For example: Added a field passtest in table MyClass, type int (4), default value of 0

Mysql> ALTER TABLE MyClass add passtest int (4) default "0"


9. Change the table name:

Command: Rename TableThe original table name to the new table name;

For example, change the name of the table MyClass to Youclass

Mysql> Rename table MyClass to Youclass;
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.