Getting started with MySQL-quick reference (3) _ MySQL

Source: Internet
Author: User
Tags mysql command line
MySQL Getting Started Guide-quick reference (3) 9. multi-line command input

The MySQL command line interface allows a statement to be input as one line, or expanded into multiple lines. There is no syntax difference between the two. With multi-line input, you can break down SQL statements step by step to make it easier to understand.

In the multi-row mode, the annotator adds each row to the previous row until you use the semicolon ";" to end the SQL statement. Once you type a semicolon and press enter, this statement is executed.

The following example shows two input methods for the same strict SQL statement:

Single row input

Mysql> create table table33 (field01 integer, field02 char (30 ));

Multi-line input

Mysql> create table table33

-> (Field01

-> Integer,

-> Field02

-> Char (30 ));

Note that you cannot disconnect words, such:

Correct

Mysql> create table table33

-> (Field01

-> Integer,

-> Field02

-> Char (30 ));

Error

Mysql> create table table33

-> (Field01 inte

-> Ger,

-> Field02

-> Char (30 ));

When inserting or changing data, you cannot expand the string of the field to multiple rows. otherwise, press enter to store the data:

Standard operation

Mysql> insert into table33 (field02)

-> Values

-> ('Who thought of foo? ');

Press enter to store data

Mysql> insert into table33 (field02)

-> Values

-> ('Who thought

-> Of foo? ');

The result is as follows:

Mysql> select * from table33;

Field01 field02

NULL who thought of foo?

NULL who thought

Of foo?

10. table data embedding

Mysql> insert into table01 (field01, field02, field03, field04, field05) values

-> (2, 'second', 'Another ', '2017-10-23', '10: 30: 00 ');

Query OK, 1 row affected (0.00 sec)

The standard date format is "yyyy-mm-dd ".

The standard time format is "hh: mm: ss ".

The quotation marks must be in the preceding standard date and time format.

The date format can also be "yyyymmdd" or "hhmmss", but the value does not need to be enclosed in quotation marks.

No quotation marks are required for numeric values. This type of storage is irrelevant to the data type. these data types are included in formatted columns (such as text, date, time, and integer ).

MySQL has a very useful Command buffer. It saves the SQL statement you have already typed and used it. for the same command, you do not have to repeat the input over and over again. Next, let's look at this example.

Add another data using the command buffer (and any date and time format)

Press the up arrow on the keyboard twice.

Press Enter.

Enter a new value in parentheses and end with a semicolon.

(3, 'a third', 'more', 19991024,103 004 );

Press Enter.

Is the new value included?

Mysql> select * from table01;

Field01 field02 field03 field04 field05

1 first NULL

2 second another 10:30:00

3 a third more 10:30:04

11. update table data

Modify a field at a time

Pay attention to the syntax again. The text must be enclosed in quotation marks but not digits.

Mysql> update table01 set field03 = 'new info' where field01 = 1;

Query OK, 1 row affected (0.00 sec)

Change multiple fields at a time

Remember to separate each Updated field with a comma.

Mysql> update table01 set field04 = 19991022, field05 = 062218 where field01 = 1;

Query OK, 1 row affected (0.00 sec)

Update multiple data at a time

Mysql> update table01 set field05 = 152901 where field04> 19990101;

Query OK, 3 rows affected (0.00 sec)

12. delete data

Mysql> delete from table01 where field01 = 3;

Query OK, 1 row affected (0.00 sec)

13. exit

Mysql> quit

Bye

Now you know some basic commands for running databases in MySQL. Because MySQL is operated by executing SQL calls, you need an adequate array of powerful tools in your processing. For example, by joining related fields, you can display data in several tables at the same time. Similarly, SQL allows you to comprehensively display, update, or delete multiple data that meets specific standards. If you want to master it, you need to learn all the SQL knowledge in the next step.

In addition, MySQL provides good network operation security features. For more information about MySQL security and other features, see the MySQL website: http://www.mysql.com

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.