MySQL Basic application

Source: Internet
Author: User

1. Log in to the MySQL server

[Email protected] ~]# mysql-u root-p

Enter Password://Follow the prompts to enter the correct password

2. Execute the MySQL action statement

Execute "show master Logs" after logging into "mysql>" environment with Root; Statement to query the log file information for the current database service.

3. Exit the "MySQL" Operating environment

Execute the "exit" or "quit" command in the "mysql>" operating environment to exit the MySQL command tool and return to the shell environment.

4. View the database structure

Show DATABASE statement: Used to view the libraries contained in the current MySQL server.

Show Tables statement: Used to view the tables contained in the current database. Before you do this, you need to switch to the library you are using with the USE statement.

Describe statement: The structure used to represent the information that makes up the various fields (columns) of the table. You need to specify "library name. Table name" as the parameter;

5. Create and delete libraries and tables

Create a new library

Create DATABASE auth; Create a table named Auth.

Create a new table

CREATE TABLE table name (field 1 name type, field 2 name Type,..., PRIMARY KET (primary key name))

Delete a database

DROP database auth.users;

Delete a data table

drop table auth;

6. Data records in the table

INSERT INTO statement: Used to insert a new data record into a table.

Insert into table name (Field 1, field 2 ...) VALUES (Value of field 1, Value of field ...)

Example: The section of the specified field in the INSERT statement can be omitted. Insert into users values (' Lucky ', password ' 1234 ');

Select statement: Finds a matching data record from the specified table.

Select Field Name 1, field name 2,... from table name condition expression

Example: SELECT * from Auth.users;

UPDATE statement: Used to modify and update data records.

Update table name SET field Name 1 = field value 1[, field 2 = field value 2] Where condition expression

Example: Update auth.users SET User_passwd=password (") where user_name= ' lucky ';

Delete statement: Used to delete the data records specified by the intermediate table.

Delete from table name where conditional expression

Example: Delete from auth.users where user_name= ' lucky '

7. Database Backup Recovery

Backing Up the database

Format 1: Export Some of the tables in the library.

mysqldump [Options] Library name [table name 1] [table Name 2] ... >/backup path/backup file name

Format 2: Export one or more complete libraries.

mysqldump [options]--databases library name 1 [library Name 2] ... >/backup path/backup file name

Format 3: Back up all libraries in the MySQL server.

mysqldump [Options]--all-database >/backup path/backup file name

Example: mysqldump-u root-p mysql user > Mysql-user.sql

Mysqldump-u root-p--databases auth > Auth.sql

Recovering a Database

mysql [options] [library name] [table name] </backup path/backup file name

Mysql-u root-p Test < Mysql-user.sql

What dreams are, dreams are a way to make you feel insisted is a happy thing.

This article from "Lucky" blog, reproduced please contact the author!

MySQL Basic application

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.