apache-ignite
225 строк · 6.1 Кб
1// Licensed to the Apache Software Foundation (ASF) under one or more
2// contributor license agreements. See the NOTICE file distributed with
3// this work for additional information regarding copyright ownership.
4// The ASF licenses this file to You under the Apache License, Version 2.0
5// (the "License"); you may not use this file except in compliance with
6// the License. You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15= Using SQLLine With Apache Ignite
16
17
18Command line tool for SQL connectivity.
19
20== Overview
21Apache Ignite is shipped with the SQLLine tool – a console-based utility for connecting to relational databases and executing SQL commands.
22This documentation describes how to connect SQLLine to your cluster, as well as various supported SQLLine commands.
23
24== Connecting to Ignite Cluster
25From your {IGNITE_HOME}/bin directory, run `sqlline.sh -u jdbc:ignite:thin:[host]` to connect SQLLine to the cluster. Substitute [host] with your actual value. For example:
26
27[tabs]
28--
29tab:Unix[]
30[source,shell]
31----
32./sqlline.sh --verbose=true -u jdbc:ignite:thin://127.0.0.1/
33----
34
35tab:Windows[]
36[source,shell]
37----
38sqlline.bat --verbose=true -u jdbc:ignite:thin://127.0.0.1/
39----
40
41--
42
43
44
45Use the `-h` or `help` option to see the various options available with SQLLine:
46
47[tabs]
48--
49tab:Unix[]
50[source,shell]
51----
52./sqlline.sh -h
53./sqlline.sh --help
54----
55
56tab:Windows[]
57[source,shell]
58----
59sqlline.bat -h
60sqlline.bat --help
61----
62--
63
64
65=== Authentication
66If you have authentication enabled for your cluster, then from your `{IGNITE_HOME}/bin' directory, run `jdbc:ignite:thin://[address]:[port];user=[username];password=[password]` to connect SQLLine to the cluster. Substitute `[address]`, `[port]`, `[username]` and `[password]` with your actual values. For example:
67
68
69[tabs]
70--
71tab:Unix[]
72[source,shell]
73----
74./sqlline.sh --verbose=true -u "jdbc:ignite:thin://127.0.0.1:10800;user=ignite;password=ignite"
75----
76
77tab:Windows[]
78[source,shell]
79----
80sqlline.bat --verbose=true -u "jdbc:ignite:thin://127.0.0.1:10800;user=ignite;password=ignite"
81----
82--
83
84If you do not have authentication set, omit `[username]` and `[password]`.
85
86[NOTE]
87====
88[discrete]
89=== Put JDBC URL in Quotes When Connecting from bash
90Make sure to put the connection URL in " " quotes when connecting from a bash environment, as follows: "jdbc:ignite:thin://[address]:[port];user=[username];password=[password]"
91====
92
93== Commands
94Here is the list of supported link:http://sqlline.sourceforge.net#commands[SQLLine commands, window=_blank]:
95
96[width="100%", cols="25%, 75%"]
97|=======
98|Command | Description
99
100|`!all`
101|Execute the specified SQL against all the current connections.
102
103|`!batch`
104|Start or execute a batch of SQL statements.
105
106|`!brief`
107|Enable terse output mode.
108
109|`!closeall`
110|Close all current open connections.
111
112|`!columns`
113|Display columns of a table.
114
115|`!connect`
116|Connect to a database.
117
118|`!dbinfo`
119|List metadata information about the current connection.
120
121|`!dropall`
122|Drop all tables in the database.
123
124|`!go`
125|Change to a different active connection.
126
127|`!help`
128|Display help information.
129
130|`!history`
131|Display the command history.
132
133|`!indexes`
134|Display indexes for a table.
135
136|`!list`
137|Display all active connections.
138
139|`!manual`
140|Display SQLLine manual.
141
142|`!metadata`
143|Invoke arbitrary metadata commands.
144
145|`!nickname`
146|Create a friendly name for the connection (updates command prompt).
147
148|`!outputformat`
149|Change the method for displaying SQL results.
150
151|`!primarykeys`
152|Display the primary key columns for a table.
153
154|`!properties`
155|Connect to the database defined in the specified properties file.
156
157|`!quit`
158|Exit SQLLine.
159
160|`!reconnect`
161|Reconnect to the current database.
162
163|`!record`
164|Begin recording all output from SQL commands.
165
166|`!run`
167|Execute a command script.
168
169|`!script`
170|Save executed commands to a file.
171
172|`!sql`
173|Execute a SQL against a database.
174
175|`!tables`
176|List all the tables in the database.
177
178|`!verbose`
179|Enable verbose output mode.
180|=======
181
182Note that the above list may not be complete. Support for additional SQLLine commands can be added.
183
184== Example
185After connecting to the cluster, you can execute SQL statements and SQLLine commands:
186
187
188Create tables:
189[source,sql]
190----
1910: jdbc:ignite:thin://127.0.0.1/> CREATE TABLE City (id LONG PRIMARY KEY, name VARCHAR) WITH "template=replicated";
192No rows affected (0.301 seconds)
193
1940: jdbc:ignite:thin://127.0.0.1/> CREATE TABLE Person (id LONG, name VARCHAR, city_id LONG, PRIMARY KEY (id, city_id))WITH "backups=1, affinityKey=city_id";
195No rows affected (0.078 seconds)
196
1970: jdbc:ignite:thin://127.0.0.1/> !tables
198+-----------+--------------+--------------+-------------+-------------+
199| TABLE_CAT | TABLE_SCHEM | TABLE_NAME | TABLE_TYPE | REMARKS |
200+-----------+--------------+--------------+-------------+-------------+
201| | PUBLIC | CITY | TABLE | |
202| | PUBLIC | PERSON | TABLE | |
203+-----------+--------------+--------------+-------------+-------------+
204----
205
206Define indexes:
207
208[source,sql]
209----
2100: jdbc:ignite:thin://127.0.0.1/> CREATE INDEX idx_city_name ON City (name);
211No rows affected (0.039 seconds)
212
2130: jdbc:ignite:thin://127.0.0.1/> CREATE INDEX idx_person_name ON Person (name);
214No rows affected (0.013 seconds)
215
2160: jdbc:ignite:thin://127.0.0.1/> !indexes
217+-----------+--------------+--------------+-------------+-----------------+
218| TABLE_CAT | TABLE_SCHEM | TABLE_NAME | NON_UNIQUE | INDEX_QUALIFIER |
219+-----------+--------------+--------------+-------------+-----------------+
220| | PUBLIC | CITY | true | |
221| | PUBLIC | PERSON | true | |
222+-----------+--------------+--------------+-------------+-----------------+
223----
224
225You can also watch a link:https://www.youtube.com/watch?v=FKS8A86h-VY[screencast, window=_blank] to learn more about how to use SQLLine.
226