The article directories

      • Start and stop the MySQL service
      • Logging in and out of the MySQL service
      • MySQL common commands
      • MySQL syntax specification
      • SQL language classification
      • Common SQL commands

Start and stop the MySQL service

Method 1: Computer -- right click Manage -- Service Method 2: Run NET as an administratorstartNet Stop Service Name Net Stop Service nameCopy the code

Logging in and out of the MySQL service

Method 1: Use the mysql client as the root user. Method 2: Use the Windows client to log in to mysql [-H the hostname-P Port number 】-U a username-P password-h,-P,-The space in the middle of the u is optional, but must not be blank if the password is followed: exit or CTRL+C
Copy the code

MySQL common commands

Note: The end of each command is used; Or \ g

  • 1. View all the current databases
show databases;
Copy the code
  • 2. Open the specified library
Use the libraryCopy the code
  • 3. View all tables in the current library
show tables;
Copy the code
  • 4. View all tables in other libraries
show tables fromThe library;Copy the code
  • 5. View the current library
select database();
Copy the code
  • 6. Create the tables
create tableTable name (column name column type, column name column type,...) ;Copy the code







  • 7. View the table structure
descThe name of the table.Copy the code

  • 8. Check the server version

Method 1: Log in to the mysql server

select version();
Copy the code



Method 2: You have not logged in to the mysql server

Mysql --version or mysql --VCopy the code

MySQL syntax specification

  1. It is not case sensitive, but it is recommended that the keyword be uppercase and the table name and column name be lowercase
  2. It is best to end each command with a semicolon
  3. Each command can be indented or wrapped as required
  4. annotation

    One-line comment:# comment text

    One-line comment:-- Comment text

    Multi-line comments:/* Comment the text */

SQL language classification

DQL (Data QueryLanguage) : Data query languageselect 
DML(Data Manipulate Language): Data manipulation languageinsert, the update,deleteDDL (DataDefineLanguge) : Data definition languagecreate,drop,alterTCL (Transaction ControlLanguage) : Transaction control languagecommit,rollback
Copy the code

Common SQL commands

showThe databases; View all database use names; Opens the specified libraryshowtables ; Displays all tables in the libraryshow tables fromThe library; Displays all tables in the specified librarycreate tableTable name (field name field type, field name field type); Create a tabledescThe name of the table. View the structure of the specified tableselect * fromThe name of the table. Displays all data in the tableCopy the code