MySql official manual Study Notes 1-MySql easy to use _ MySQL
Source: Internet
Author: User
MySql official manual learning Notes 1-MySql simple Getting started bitsCN.com MySql official manual learning Notes 1-MySql simple Getting started this is some of the notes I made when learning MySql 5.1, I hope I can understand what I learned. if I could help you learn MySql in the same way, it would be even more surprising. To connect to or disconnect from a server, you usually need to provide a MySQL User name and a password. If the server is running on a machine other than the login server, you also need to specify the host name: shell> mysql-h host-u user-pEnter password: * ****** host indicates the host name of the MySQL server, and user indicates the username of the MySQL account. ******* indicates your password. If it works, you should see some introduction information after the mysql> prompt: shell> mysql-h host-u user-pEnter 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> prompt tells you that mysql is ready to enter the command for you. Some MySQL installations allow anonymous (Untitled) users to connect to servers running on local hosts. If this is the case on your machine, you should be able to call mysql to connect to the server without any options: after shell> mysql is successfully connected, you can enter QUIT (or/q) at any time at the mysql> prompt to exit: mysql> QUITBye is in Unix, or you can press control-D to disconnect the server. The following is a simple command for getting familiar with idea. the server is required to tell it the version number and current date. On the mysql> prompt, enter the following command and press the Enter key: mysql> select version (), CURRENT_DATE; // A command is usually composed of SQL statements, followed by a semicolon. + Versions + -------------- + | VERSION () | CURRENT_DATE | + ------------------- + -------------- + | 5.1.2-alpha-log | 2005-10-11 | + ----------------- + -------------- + 1 row in set (0.01 sec) mysql> In addition, mysql can input keywords in upper and 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, it indicates that you can use mysql as 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 () | + --------------------- + | 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 determines where the statement ends by looking for a termination semicolon. (In other words, mysql collects input rows but does not execute until a semicolon is seen .) 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->, mysql points out 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 know what mysql is waiting. If you do not want to execute a command that is being input, enter/c to cancel the command: mysql> SELECT-> USER ()->/cmysql> note the prompt here, after you enter/c, it switches back to mysql> and provides feedback to indicate that mysql is ready to accept a new command. The following table shows the various prompts that you can see and briefly describes the status of mysql they represent: prompt meaning mysql> prepare to accept new commands. -> 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 a single quotation mark. "> 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 enclosed by ''' or '"' (for example, 'hello' or" goodbye "), mysql allows you to enter strings that span 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 statement, press Enter 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 you that mysql expects 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 enter/c, because mysql interprets it as part of the string it is collecting! Instead, enter the closed quotation mark character (so mysql knows that you have completed the string), AND then enter/c: mysql> SELECT * FROM my_table WHERE name = 'Smith AND age <30; '>'/cmysql> prompt back to mysql>, it shows that mysql is 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. Knowing '> and "> The meaning of the prompt is very important, because if you mistakenly enter an unterminated string, any rows entered later will be ignored by mysql-including 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
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.