MySql official manual study notes 1MySql easy start _ MySQL

Source: Internet
Author: User
MySql official manual study notes 1MySql easy to get started bitsCN.com

Connect to and disconnect the server

A MySQL User name and a password are usually required to connect to the server. If the server runs on a machine other than the login server, you must specify the host name:
shell> mysql -h host -u user -p
Enter password: ********

Host indicates the host name of the MySQL server, user indicates the MySQL account user name, and ******* indicates your password.

If valid, you should see some introduction information after the mysql> prompt:

shell> mysql -h host -u user -p
Enter password: ********
Welcome to the MySQL monitor.  Commands end with ; or /g.
Your MySQL connection id is 25338 to server version: 5.1.2-alpha-standard
 
Type 'help;' or '/h' for help. Type '/c' to clear the buffer.
 
mysql>

Mysql> the prompt tells you that mysql is ready to enter the command for you.

SomeMySQLThe installation allows anonymous (Untitled) users to connect to the server running on the local host. If your machine is in this situation, you should be able to call it without any options.MysqlConnect to the server:

shell> mysql

After successful connection, you can enter QUIT (or/q) at the mysql> prompt to exit at any time:

mysql> QUIT
Bye

In Unix, you can also press control-D to disconnect the server.

Easy to understand

The following is a simple command that requires the server to tell it the version number and current date. In mysql, enter the following command and press enter:

Mysql>Select version (), CURRENT_DATE;//A command is usually composedSQLStatement, followed by a semicolon.
+-----------------+--------------+
| VERSION()       | CURRENT_DATE |
+-----------------+--------------+
| 5.1.2-alpha-log | 2005-10-11   |
+-----------------+--------------+
1 row in set (0.01 sec) 
mysql>

In addition,MysqlKeywords can be entered in upper or lower case. The following queries are equivalent:

mysql> SELECT VERSION(), CURRENT_DATE;
mysql> select version(), current_date;
mysql> SeLeCt vErSiOn(), current_DATE;

This is another query, which indicates that you canMysqlAs a simple calculator:

mysql> SELECT SIN(PI()/4), (4+1)*5;
+------------------+---------+
| SIN(PI()/4)      | (4+1)*5 |
+------------------+---------+
| 0.70710678118655 |      25 |
+------------------+---------+
1 row in set (0.02 sec)

The command displayed here is a very short single-line statement. You can enter multiple statements on one line. you only need to separate the statements with one semicolon:

mysql> SELECT VERSION(); SELECT NOW();
+-----------------+
| VERSION()       |
+-----------------+
| 5.1.2-alpha-log |
+-----------------+
1 row in set (0.00 sec)
 
+---------------------+
| NOW()               |
+---------------------+
| 2005-10-11 15:15:00 |
+---------------------+
1 row in set (0.00 sec)

You do not need to give a command in one line. a long command can be entered into multiple lines.Mysql isDetermine where the statement ends by looking for an end semicolon. (In other words,MysqlCollect input rows, but do not execute until you see a semicolon .)

Here is an example of a simple multi-line statement:

mysql> SELECT
    -> USER()
    -> ,
    -> CURRENT_DATE;
+---------------+--------------+
| USER()        | CURRENT_DATE |
+---------------+--------------+
| jon@localhost | 2005-10-11   |
+---------------+--------------+

In this example, after entering the first line of multi-line query, note that the prompt is changed from mysql> to->.MysqlIt indicates that it does not see the complete statement and is waiting for the remaining part. The prompt is your friend, because it provides valuable feedback. if you use this feedback, you will always knowMysqlWhat is waiting.

If you decide not to execute a command in the input process, enter/c to cancel it:

mysql> SELECT
    -> USER()
    -> /c
mysql>

Note the prompt here. after you enter/c, it switches back to mysql> and provides feedback to indicateMysqlPrepare to accept a new command.

The following table shows the various prompts that you can see and briefly describesMysqlStatus:

Prompt

Description

Mysql>

Prepare to accept the new command.

->

Wait for the next line of the multi-line command.

'>

Wait for the next line, and wait for the end of the string starting with single quotes.

">

Wait for the next line, and wait for the end of the string starting with double quotation marks.

'>

Wait for the next line, and wait for the end of the identifier starting with the reverse oblique point.

/*>

Wait for the next line and wait for the end of comments starting.

A '> and "> prompt (prompting MySQL to wait for the end of the string) will appear during string collection ). In MySQL, you can write a string (for example, 'hello' or "goodbye") that is enclosed by ''' or '"', andMysqlYou can enter a string that spans multiple rows. When you see a '> or "> prompt, this means that you have entered a line containing a string starting with '''' or, however, no matching quotation marks are entered for the ending string. This shows that you accidentally omitted a quotation mark character. For example:

mysql> SELECT * FROM my_table WHERE name = 'Smith AND age < 30;
    '>

If you enter the SELECT statementEnter (Press enter)Key and wait for the result. nothing appears. Don't be surprised, "Why is the query so long ?", Note: "> clues provided by the prompt. It tells youMysqlExpect to see the rest of an unterminated string. (Do you see errors in statements? String "Smith dropped the second quotation mark .)

In this step, what should you do? The simplest is to cancel the command. However, in this case, you cannot just input/c, becauseMysqlInterpret it as part of the string it is collecting! Instead, enter the characters in the closed quotation marks (suchMysqlKnow that you have completed the string), and then enter/c:

mysql> SELECT * FROM my_table WHERE name = 'Smith AND age < 30;
    '> '/c
mysql>

Prompt back to mysql>, displayMysqlYou are ready to accept a new command.

'> The prompt is similar to'> and "> the prompt, but it indicates that you have started but not ended with '> The start identifier.

It is important to know the meanings of '> and "> the prompt, because if you mistakenly enter an unterminated string, any line entered later will beMysqlIgnore -- include rows containing QUIT! This may be confusing, especially if you do not know before canceling the current command, you need to provide the ending quotation marks.

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