MySQL Basic operations Summary

Source: Internet
Author: User

The commands commonly used in the MySQL database process are listed below:

    • use database name : Select the MySQL database you want to manipulate, and all MySQL commands are only for that database after using this command.
    • SHOW DATABASES: lists a list of databases for the MySQL database management system.
    • Show TABLES: Displays all tables for the specified database and uses the use command to select the database to manipulate before using the command.
    • show COLUMNS from data table : Displays data table properties, property types, primary key information, whether null, default value, and other information.
    • Show index from data table : displays detailed index information for the data table, including primary key (primary key).
    • SHOW table STATUS like datasheet \g: This command will output the performance and statistics of the MySQL database management system.

Database operations:

Login database:

Mysql-u root-p ' passwd '-P 3306

To exit the database:

Ctrl+d or quit

To modify the database login password (shell command line):

mysqladmin-u root-p Password New password

To create a database:

CREATE DATABASE Mysql_name;

To delete a database:

DROP DATABASE Mysql_name;

View all databases:

SHOW DATABASES;

Open the database:

Use Mysql_name;

Displays the database that was opened;

SELECT Databas ();

Table Operation:

To create a table:

CREATE TABLE table_name (column declaration);

Example: CREATE TABLE student (

ID INT UNSIGNED not NULL PRIMARY KEY auto_increment,

Name CHAR (Ten) is not NULL,

Age TINYINT Not NULL

);

View all the tables:

SHOW TABLES;

To delete a table:

DROP TABLE table_name;

To view the data table structure:

SHOW COLUMNS from table_name;

To rename a table:

ALTER TABLE old_table_name RENAME new_table_name;

Insert data:

INSERT TABLE table_name (column name) values (value);

Delete data:

DELETE from table name [where condition];

To query the data in a table:

SELECT column name from table name [where condition];

Updating data in a table

UPDATE table name SET column name = new value [Where condition];

Querying all data in a table (using wildcard characters)

SELECT * FROM table_name;

The ALTER TABLE statement is used to modify the table after it is created, using the following basic usage

Adding columns

ALTER table name add column Name column data type [after ...] ;

Delete Column

ALTER table name DROP column name;

modifying columns

ALTER table name change column name new column name new data type;

Adjustments to constraints:

  

MySQL Basic operations Summary

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.