MySQL Operation detailed

Source: Internet
Author: User
Tags import database

Create and use a database
    • To view the database on the server:SHOW DATABASES;
    • To create a database:CREATE DATABASE <数据库名>;
    • Indicate what database to use:USE <数据库名>
Create and use a table
    • To create a table:CREATE TABLE <表名> (<列名> <数据类型> <约束>,...);
    • View tables (These tables are available in this database):SHOW TABLES;
    • View table structure (column name, data type, constraints, etc.):DESCRIBE <表名>;
    • File Data Import Database:LOAD DATA INFILE <文件> INTO TABLE <表名>;
    • Read all the information from the table:SELECT * FROM <表名>;
    • To obtain a time difference (for example, for calculating age): e.g.: SELECT name,TIMESTAMPDIFF(YEAR,<列名>,CURDATE()) AS age FROM pet; orSELECT name,(YEAR(CURDATE())-YEAR(<列名>-(RIGHT(CURDATE(),5)<RIGHT(<列名>,5)) AS age FROM pet;
    • Null value: null indicates an unknown value. Regarding NULL, it should be noted that: 1. Determine whether a data is null, should be used <列名> IS NULL/IS NOT NULL ; 2.GROUP by two values null are considered equal; 3.0 or an empty string is not null
    • Support pattern matching in conditional statements where, regular expressions
    • Use COUNT() function count
    • In MySQL, you can connect two tables directly using the FROM clause
Getting information about a database and tables
    • Get all databases under the server:SHOW DATABASES;
    • Get the currently used database:SELECT DATABASE();
    • Get all tables in the database:SHOW TABLES;
    • Get table structure:DESCRIBE <表名>;
    • Gets the index information for the table:SHOW INDEX FROM <表名>;

MySQL Operation detailed

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.