MySQL common command operation tips for beginners

Source: Internet
Author: User

Last time we introduced: Suitable for beginnersMySQLSummary of Common Operations of the Study Notes administrator. Here we will introduce the MySQL Study NotesCommon commandsNext, let's take a look at this part.

Operation Skills

1. If you forget the extra points after you press Enter when making the command, you don't have to repeat the command. You just need to press a semicolon to press Enter. That is to say, you can divide a complete command into several lines, and then use a semicolon as the end sign to complete the operation.

2. You can use the cursor to bring up or down the previous commands. However, an old MYSQL version I used earlier does not support this feature. I am using a mysql-3.23.27-beta-win.

Display command

1. DisplayDatabaseList.

Show databases;

At the beginning, there were only two databases: mysql and test. The mysql database contains the MYSQL system information. We change the password and add new users to use this database for operations.

2. display the data tables in the database:

Use mysql; // open the database. If you have learned FOXBASE, you will not be unfamiliar with it.

Show tables;

3. display the data table structure:

Describe table name;

4. database creation:

Create database name;

5. Create a table:

Use Database Name;

Create table Name (field setting list );

6. Delete databases and tables:

Drop database name;

Drop table name;

7. Clear records in the table:

Delete from table name;

8. Display records in the table:

Select * from table name;

An instance for creating a database, creating a table, and inserting data

 
 
  1. Drop database if exists school; // Delete if SCHOOL exists
  2. Create database school; // create a database SCHOOL
  3. Use school; // open the SCHOOL library
  4. Create table teacher // create table TEACHER
  5. (
  6. Id int (3) auto_increment not null primary key,
  7. Name char (10) not null,
  8. Address varchar (50) default 'shenzhen ',
  9. Year date
  10. ); // Table creation ends
  11. // Insert fields as follows
  12. Insert into teacher values ('', 'glengang ', 'shenzhen Zhongyi', '2017-10-10 ');
  13. Insert into teacher values ('', 'jack', 'shenzhen Zhongyi ', '2017-12-23 ');

Note:

1) set the ID to a numeric field of 3: int (3) and let it automatically add one: auto_increment for each record. It cannot be blank: not null and make it the primary key.

2) Set NAME to a 10-character field.

3) set ADDRESS to a 50-character field, and the default value is Shenzhen. What is the difference between varchar and char? It will only be discussed later.

4) set YEAR as the date field.

If you type the preceding command at the mysql prompt, debugging is not convenient. You can write the above commands into a text file as they are. SQL, then copy to c: \, and enter the directory \ mysql \ bin in DOS status, and then enter the following command: mysql-uroot-p password <c: \ school. if the SQL statement is successful, no display is displayed for a blank row. If an error occurs, a prompt is displayed. The preceding command has been debugged. You only need to remove the // annotation to use it ).

Convert text data to a database

1. Text data should conform to the format: field data is separated by the tab key, and the null value is replaced by \ n.

Example:

3 rose:

4 mike: Shenzhen No. 1,-12-23

2. data Import command load data local infile "file name" into table name;

Note: You 'd better copy the file to the \ mysql \ bin directory and use the use command to create the database where the table is located.

Back up database

Run the following command in the \ mysql \ bin directory of DOS:

Mysqldump -- opt school> school. bbb

Note: Back up the database school to the school. bbb file. school. bbb is a text file with any file name. Open it and you will find new discoveries.

This section describes the MySQL command and operation skills that are suitable for beginners. I hope this introduction will be helpful to you!

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.