Home Database Mysql Tutorial MySQL中文参考手册--输入查询_MySQL

MySQL中文参考手册--输入查询_MySQL

Jun 01, 2016 pm 01:54 PM
Reference book how server Knowledge

确保你连接上了服务器,如在先前的章节讨论的。这样做本身将不选择任何数据库来工作,但是那很好。从这点讲,知道关于如何出询问的一点知识,比马上跳至创建表、给他们装载数据并且从他们检索数据要来的重要写。本节描述输入命令的基本原则,使用几个查询,你能尝试让自己mysql是如何工作的。
  
  这是一个简单的命令,要求服务器告诉你它的版本号和当前日期。在mysql>提示打入如下命令并按回车键:
  
  mysql> SELECT VERSION(), CURRENT_DATE;
  +--------------+--------------+
  | version()  | CURRENT_DATE |
  +--------------+--------------+
  | 3.22.20a-log | 1999-03-19  |
  +--------------+--------------+
  1 row in set (0.01 sec)
  mysql>
  
  这询问说明关于mysql几件事:
  一个命令通常由SQL语句组成,随后有一个分号。(有一些例外不需要一个分号。早先提到的QUIT是他们之一。我们将以后看到其它。)
  当你发出一个命令时,mysql发送它给服务器并显示结果,然后打出另外一个mysql>显示它准备好接受另外的命令。
  mysql以一张表格(行和列)显示查询输出。第一行包含列的标签,随后的行是询问结果。通常, 列标签是你取自数据库表的列的名字。如果你正在检索一个表达式而非表列的值(如刚才的例子),mysql用表达式本身标记列。
  mysql显示多少行被返回,和查询花了多长执行,它给你提供服务器性能的一个大致概念。因为他们表示时钟时间(不是 CPU 或机器时间),并且因为他们受到诸如服务器负载和网络延时的影响,因此这些值是不精确的。(为了简洁,在本章剩下的例子中不再显示“集合中的行”。)
  关键词可以以任何大小写字符被输入。下列询问是等价的:
  
  mysql> SELECT VERSION(), CURRENT_DATE;
  mysql> select version(), current_date;
  mysql> SeLeCt vErSiOn(), current_DATE;
  
  这里有另外一个查询,它说明你能将mysql用作一个简单的计算器:
  mysql> SELECT SIN(PI()/4), (4+1)*5;
  +-------------+---------+
  | SIN(PI()/4) | (4+1)*5 |
  +-------------+---------+
  |  0.707107 |   25 |
  +-------------+---------+
  
  至今显示的命令是相当短的,单行语句。你甚至能在单行上输入多条语句,只是以一个分号结束每一条:
  
  mysql> SELECT VERSION(); SELECT NOW();
  +--------------+
  | version()  |
  +--------------+
  | 3.22.20a-log |
  +--------------+
  
  +---------------------+
  | NOW()        |
  +---------------------+
  | 1999-03-19 00:15:33 |
  +---------------------+
  
  一个命令不必全在一个单独行给出,所以需要多行的较长命令不是一个问题。mysql通过寻找终止的分号而不是寻找输入行的结束来决定你的语句在哪儿结束。(换句话说,mysql接受自由格式输入:它收集输入行但执行他们直到它看见分号。)
  
  这里是一个简单的多行语句的例子:
  
  mysql> SELECT
    -> USER()
    -> ,
    -> CURRENT_DATE;
  +--------------------+--------------+
  | USER()       | CURRENT_DATE |
  +--------------------+--------------+
  | joesmith@localhost | 1999-03-18  |
  +--------------------+--------------+
  在这个例子中,在你输入一个多行查询的第一行后,要注意提示符如何从mysql>变为->,这正是mysql如何指出它没见到完整的语句并且正在等待剩余的部分。提示符是你的朋友,因为它提供有价值的反馈,如果你使用该反馈,你将总是知道mysql正在等待什么。
  
  如果你决定,你不想要执行你在输入过程中输入的一个命令,打入/c取消它:
  
  mysql> SELECT
    -> USER()
    -> /c
  mysql>
  
  这里也要注意提示符,在你打入/c以后,它切换回到mysql>,提供反馈以表明mysql准备接受一个新命令。
  
  下表显示出你可以看见的各个提示符并总结他们意味着mysql在什么状态下:
  
  提示符 意思 
  mysql> 准备好接受新命令
  -> 等待多行命令的下一行
  '> 等待下一行,收集以单引号(“'”)开始的字符串 
  "> 等待下一行,收集以双引号(“"”)开始的字符串
  
  当你打算在一个单行上发出一个命令时,多行语句通常“偶然”出现,但是忘记终止的分号。在这种情况中,mysql等待进一步输入:
  
  mysql> SELECT USER()
    ->
  
  如果这发生在你身上(你认为你输完了语句但是唯一的反应是一个->提示符),很可能mysql正在等待分号。如果你没有注意到提示符正在告诉你什么,在认识到你需要做什么之前,你可能花一会儿时间呆坐在那儿。进入一个分号完成语句,并且mysql将执行它:
  
  mysql> SELECT USER()
    -> ;
  +--------------------+
  | USER()       |
  +--------------------+
  | joesmith@localhost |
  +--------------------+
  
  '>和">提示符出现在在字符串收集期间。在MySQL中,你可以写由“'”或“"”字符括起来的字符串 (例如,'hello'或"goodbye"),并且mysql让你进入跨越多行的字符串。当你看到一个'>或">提示符时,这意味着你已经输入了包含以“'”或“"”括号字符开始的字符串的一行,但是还没有输入终止字符串的匹配引号。如果你确实正在输入一个多行字符串,很好,但是果真如此吗?不尽然。更常见的,'>和">提示符显示你粗心地省掉了一个引号字符。例如:
  
  mysql> SELECT * FROM my_table WHERE name = "Smith AND age     ">
  如果你输入该SELECT语句,然后按回车键并等待结果,什么都没有出现。不要惊讶,“为什么该查询这么长呢?”,注意">提示符提供的线索。它告诉你mysql期望见到一个未终止字符串的余下部分。(你在语句中看见错误吗?字符串"Smith正好丢失第二个引号。)
  走到这一步,你该做什么?最简单的是取消命令。然而,在这种情况下,你不能只是打入/c,因为mysql作为它正在收集的字符串的一部分来解释它!相反,输入关闭的引号字符(这样mysql知道你完成了字符串),然后打入/c:
  
  mysql> SELECT * FROM my_table WHERE name = "Smith AND age     "> "/c
  mysql>
  
  提示符回到mysql>,显示mysql准备好接受一个新命令了。
  
  知道'>和">提示符意味着什么是很重要的,因为如果你错误地输入一个未终止的字符串,任何比你下一步输入的行好象将要被mysql忽略--包括包含QUIT的行!这可能相当含糊,特别是在你能取消当前命令前,如果你不知道你需要提出终止引号

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve the problem that eMule search cannot connect to the server How to solve the problem that eMule search cannot connect to the server Jan 25, 2024 pm 02:45 PM

Solution: 1. Check the eMule settings to make sure you have entered the correct server address and port number; 2. Check the network connection, make sure the computer is connected to the Internet, and reset the router; 3. Check whether the server is online. If your settings are If there is no problem with the network connection, you need to check whether the server is online; 4. Update the eMule version, visit the eMule official website, and download the latest version of the eMule software; 5. Seek help.

Solution to the inability to connect to the RPC server and the inability to enter the desktop Solution to the inability to connect to the RPC server and the inability to enter the desktop Feb 18, 2024 am 10:34 AM

What should I do if the RPC server is unavailable and cannot be accessed on the desktop? In recent years, computers and the Internet have penetrated into every corner of our lives. As a technology for centralized computing and resource sharing, Remote Procedure Call (RPC) plays a vital role in network communication. However, sometimes we may encounter a situation where the RPC server is unavailable, resulting in the inability to enter the desktop. This article will describe some of the possible causes of this problem and provide solutions. First, we need to understand why the RPC server is unavailable. RPC server is a

Detailed explanation of CentOS installation fuse and CentOS installation server Detailed explanation of CentOS installation fuse and CentOS installation server Feb 13, 2024 pm 08:40 PM

As a LINUX user, we often need to install various software and servers on CentOS. This article will introduce in detail how to install fuse and set up a server on CentOS to help you complete the related operations smoothly. CentOS installation fuseFuse is a user space file system framework that allows unprivileged users to access and operate the file system through a customized file system. Installing fuse on CentOS is very simple, just follow the following steps: 1. Open the terminal and Log in as root user. 2. Use the following command to install the fuse package: ```yuminstallfuse3. Confirm the prompts during the installation process and enter `y` to continue. 4. Installation completed

How to configure Dnsmasq as a DHCP relay server How to configure Dnsmasq as a DHCP relay server Mar 21, 2024 am 08:50 AM

The role of a DHCP relay is to forward received DHCP packets to another DHCP server on the network, even if the two servers are on different subnets. By using a DHCP relay, you can deploy a centralized DHCP server in the network center and use it to dynamically assign IP addresses to all network subnets/VLANs. Dnsmasq is a commonly used DNS and DHCP protocol server that can be configured as a DHCP relay server to help manage dynamic host configurations in the network. In this article, we will show you how to configure dnsmasq as a DHCP relay server. Content Topics: Network Topology Configuring Static IP Addresses on a DHCP Relay D on a Centralized DHCP Server

Best Practice Guide for Building IP Proxy Servers with PHP Best Practice Guide for Building IP Proxy Servers with PHP Mar 11, 2024 am 08:36 AM

In network data transmission, IP proxy servers play an important role, helping users hide their real IP addresses, protect privacy, and improve access speeds. In this article, we will introduce the best practice guide on how to build an IP proxy server with PHP and provide specific code examples. What is an IP proxy server? An IP proxy server is an intermediate server located between the user and the target server. It acts as a transfer station between the user and the target server, forwarding the user's requests and responses. By using an IP proxy server

What should I do if I can't enter the game when the epic server is offline? Solution to why Epic cannot enter the game offline What should I do if I can't enter the game when the epic server is offline? Solution to why Epic cannot enter the game offline Mar 13, 2024 pm 04:40 PM

What should I do if I can’t enter the game when the epic server is offline? This problem must have been encountered by many friends. When this prompt appears, the genuine game cannot be started. This problem is usually caused by interference from the network and security software. So how should it be solved? The editor of this issue will explain I would like to share the solution with you, I hope today’s software tutorial can help you solve the problem. What to do if the epic server cannot enter the game when it is offline: 1. It may be interfered by security software. Close the game platform and security software and then restart. 2. The second is that the network fluctuates too much. Try restarting the router to see if it works. If the conditions are OK, you can try to use the 5g mobile network to operate. 3. Then there may be more

How to install PHP FFmpeg extension on server? How to install PHP FFmpeg extension on server? Mar 28, 2024 pm 02:39 PM

How to install PHPFFmpeg extension on server? Installing the PHPFFmpeg extension on the server can help us process audio and video files in PHP projects and implement functions such as encoding, decoding, editing, and processing of audio and video files. This article will introduce how to install the PHPFFmpeg extension on the server, as well as specific code examples. First, we need to ensure that PHP and FFmpeg are installed on the server. If FFmpeg is not installed, you can follow the steps below to install FFmpe

Detailed explanation of the advantages and utility of Golang server Detailed explanation of the advantages and utility of Golang server Mar 20, 2024 pm 01:51 PM

Golang is an open source programming language developed by Google. It is efficient, fast and powerful and is widely used in cloud computing, network programming, big data processing and other fields. As a strongly typed, static language, Golang has many advantages when building server-side applications. This article will analyze the advantages and utility of Golang server in detail, and illustrate its power through specific code examples. 1. The high-performance Golang compiler can compile the code into local code

See all articles