Introduction to MySQL database in practical application

Source: Internet
Author: User
This article mainly describes the operations on the actual application of the MySQL database. However, you must first log on to the MySQL database. The following operations are performed at the actual prompt of the MySQL database, and each related command must end with a semicolon. I. Operation Tips 1. If you forget the extra score when you press enter, you do not need to repeat it.

This article mainly describes the operations on the actual application of the MySQL database. However, you must first log on to the MySQL database. The following operations are performed at the actual prompt of the MySQL database, and each related command must end with a semicolon. I. Operation Tips 1. If you forget the extra score when you press enter, you do not need to repeat it.

This article mainly describes the operations on the actual application of the MySQL database. However, you must first log on to the MySQL database. The following operations are performed at the actual prompt of the MySQL database, and each related command must end with a semicolon.

I. 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.

Ii. Display commands

1. display the list of databases on the current MySQL Database Server:

MySQL> show databases;

Note: 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 MySQL database:

MySQL> USE Database Name;

MySQL> show tables;

3. display the data table structure:

MySQL> DESCRIBE table name;

4. Create a MySQL database:

MySQL> create database name;

5. Create a data table:

MySQL> USE Database Name;

MySQL> create table Name (field name VARCHAR (20), field name CHAR (1 ));

6. delete a MySQL database:

MySQL> drop database name;

7. delete a data table:

MySQL> drop table name;

8. Clear records in the table:

MySQL> delete from table name;

9. display the records in the table:

MySQL> SELECT * FROM table name;

10. insert records into the table:

MySQL> insert into table name VALUES ("hyq", "M ");

11. Update table data:

MySQL-> UPDATE table name: SET field name: 1 = 'a'; field name: 2 = 'B' WHERE field name: 3 = 'C ';

12. load data into a data table in text mode:

MySQL> load data local infile "D:/MySQL.txt" into table name;

13. Import the. SQL FILE command:

MySQL> USE Database Name;

MySQL> SOURCE d:/MySQL. SQL;

14. Change the root password on the command line:

MySQL> UPDATE MySQL. user SET password = PASSWORD ('new password') WHERE User = 'root ';

MySQL> flush privileges;

15. display the MySQL database name for use:

MySQL> select database ();

16. display the current user:

MySQL> select user ();

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

Drop database if exists school; // Delete if SCHOOL exists

Create database school; // create a database SCHOOL

Use school; // open the SCHOOL library

Create table teacher // create table TEACHER

(

Id int (3) auto_increment not null primary key,

Name char (10) not null,

Address varchar (50) default 'shenzhen ',

Year date

); // Table creation ends

// Insert fields as follows

Insert into teacher values (", 'allen ', 'dalian Zhongyi', '2017-10-10 ′);

Insert into teacher values (", 'jack', 'dalian No. 2 middle school ', '2017-12-23 ′);

If you type the preceding command at the MySQL prompt, debugging is not convenient.

(1) You can write the above commands into a text file as they are, for example, school. SQL, then copy it to c: \, and enter the directory [url = file: // \ MySQL \ bin] \ MySQL \ bin [/url] in DOS status. run the following command:

MySQL-uroot-p password <c: \ school. SQL

If it succeeds, no display is displayed for a blank row. If there is an error, a prompt is displayed. (The preceding command has been debugged. You only need to remove the // annotation to use it ).

(2) You can use MySQL> source c: \ school. SQL after entering the command line, or import the school. SQL file to the database.

4. convert text data to the MySQL database

1. Text data should conform to the format: field data is separated by a tab key, and null values are replaced by [url = file: // \ n] \ n [/url. example:

3 rose Dalian No. 2 Middle School 1976-10-10

4 mike Dalian No. 1 1975-12-23

Assume that you save these two sets of data as a school.txt file and put it under the c-drive root directory.

2. data input command load data local infile "c: \ school.txt" into table name;

Note: You 'd better copy the file to the [url = file: // \ MySQL \ bin] \ MySQL \ bin [/url] Directory, use the use command to create the database where the table is located.

V. Back up databases(The command is executed in the DOS [url = file: // \ MySQL \ bin] \ MySQL \ bin [/url] Directory)

1. Export the entire database

The exported file is stored in the MySQLbin directory by default.

MySQLdump-u username-p Database Name> exported file name

MySQLdump-u user_name-p123456 database_name> outfile_name. SQL

2. Export a table

MySQLdump-u user name-p MySQL database name Table Name> exported file name

MySQLdump-u user_name-p database_name table_name> outfile_name. SQL

3. Export a MySQL database structure

MySQLdump-u user_name-p-d-add-drop-table database_name> outfile_name. SQL

-D no data-add-drop-table add a drop table before each create statement

4. Export with language Parameters

MySQLdump-uroot-p-default-character-set = latin1-set-charset = gbk-skip-opt database_name> outfile_name. SQL

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.