Changes

Jump to navigation Jump to search
1,532 bytes removed ,  12:15, 15 February 2021
no edit summary
This step by step tutorial shows article belongs to the [[Getting Started]] Guide. It tells you how to run BaseX in client-server mode from a terminal. You can copy & paste the commands to get it running on your machine.After you finished this tutorial, you will be familiar with the basic BaseX commandscommand-line.
==Startup==
see the [[Startup Overview]].==Server==
==First Operations==To get familiar with BaseX we suggest to execute the following basic operationsThe database server handles concurrent [[Transaction_Management|read and write transactions]], [[User Management|manages user permissions]] and [[Logging|logs user interactions]].It can be started as follows:
===Creating a database===* Run one of the {{Code|basexserver}} or {{Code|basexserver.bat}} scripts. Add the {{Code|stop}} keyword to gracefully shut down the server.* To create a database If you need an XML documenthave installed BaseX on ''Windows'', click on the '''BaseX HTTP Server (Start)''' icon, e.g. which will start both the HTTP Server used for [[http://www.w3.org/XML/Binary/2005/03/test-data/Over100/factbook.xml factbook.xml#Web Application|Web Applications]].* Save this document to and the /basex directorydatabase server.* On With '''BaseX HTTP Server (Stop)''', you can shut down the client terminal run: <code>: > create db factbook factbookserver process.xml</code>
: ''factbook'' - is By default, the name of server listens to the database <br/>: ''factbookport {{Code|1984}}.xml'' - is Pressing {{Code|Ctrl+c}} will close all connections and databases and gracefully shut down the xml file, which is used to create the database<br/> server process.
If everything works you see the following lines:<pre>Database 'factbook' created in 1950Various [[Command-Line_Options#Server|command-line options]] are available to simplify batch processing.83 ms.</pre> ;Where is the database stored?Databases are stored in the BaseXData directory which is located in your home folderThe [[Start_Scripts|start script]] can be adjusted for individual purposes (e. Depending on your operating system the location of your home folder variesg. For example, on a mac it's /Users/John, if your name the default memory limit is Johntoo restrictive).
==Client=Executing a query===The [[Commands|xquery]] command lets you run a query.* For example, this query returns all country nodes in the currently opened database.<code>: > xquery //country</code>
* You can also run queries in filesDatabase clients are started similarly:<code>: > run /Users/John/query.xq</code>
===Creating a new database===* Run one of the {{Code|basexclient}} or {{Code|basexclient.bat}} scripts.Now we will create another database. You can find * Execute the example document herefollowing command: [http://phobos101{{Code|java -cp BaseX.infjar org.uni-konstanzbasex.de/basex/demo]BaseXClient}}* If you have installed BaseX on ''Windows'', click on the '''BaseX Client''' icon.
* Create the new databaseAt startup, named 'xmark'you need to enter your credentials.<code>: > create db xmark xmarkThe initial passwort of the {{Code|admin}} user is {{Code|admin}}; it can be changed with the {{Code|[[Commands#PASSWORD|PASSWORD]]}} command.xml</code>
* Set For further details, have a look at the new database xmark as [[Command-Line_Options#Client|command-line options]] and the context:<code>: > open xmark</code>[[Start_Scripts|start script]].
* Now you can easily execute queries on your new database:<code>: > xquery //people/person/name</code>=Introduction=
===Switching the database===* You can explicitly query The BaseX command-line client provides similar features to the factbook database with the doc()[[Command-funtion, no matter what Line Client|standalone client]]. The major difference is that all commands will be executed by the current context isBaseX server instance.<code>: > xquery doc("factbook")As a consequence, paths//country</code> * Otherwise, URIs to resources need to set factbook as be resolvable by the current context, execute server (file contents will not be transfered to the following:<code>: > open factbook</code> * To list the current context, type:<code>: > show databases</code> That yields the following lines:server).
Username and password can also be specified as command-line option. To evaluate commands without entering the console mode, you can use the <code>-c</code> option on the command line:
<pre>
1 opened database(s):basexclient - factbook (1x)V -Uadmin -Padmin -c "CREATE DB input <example/pre>; XQUERY /"
Database 'input' created in 13.85 ms.
<example/>
Query:
/
===Closing or deleting a database===Parsing: 0.18 ms* To [[Commands|close]] the current context database typeCompiling: 0.04 ms<code>Evaluating: 0.12 msPrinting: > close0.07 ms</code>Total Time: 0.41 ms
* Use the [[Commands|drop]] command to delete the xmark databaseHit(s): 1 ItemUpdated:0 Items<code>Printed: 10 BytesRead Locking: > drop db xmarklocal [input]</code>Write Locking: none
===Creating a collection==='''What is a collection?'''With BaseX you can group documents into one logical collection. A collection is a database that contains two or more documents. Collections accept any type of XML documents, regardless of their structure. Let's add the xmark.xml document to the factbook database to create a collection. The name of the original factbook database remains. * First make sure factbook is opened:<code>: > open factbook</code> * Now add the xmark.xml document: <code>: > add xmark.xml</code> ===Deleting a document from a collection===* Deleting a document from a collection is very easy:<code>: > delete xmark.xml</code> Make sure the collection which contains the xmarkQuery "user" executed in 0.xml document is opened41 ms===Deleting a collection===Deleting a collection is the same as deleting a database. * To delete the collection factbook, type:<code>: > drop factbook</code> ===Getting information about the server===To see all databases on the server, type::<code>> list</code> To see which database is currently opened, type::<code>> show databases</code> To see the general information of the opened database, type::<code>> info</code> To see the users in BaseX, type::<code>> show users</codepre===Backup and Restore===To backup your database, type::<code>> backup factbook</code> To restore your database, type::<code>> restore factbook</code> '''Where is the backup-file stored?'''
The backup-file is stored in the BaseXData directory, which is in your home directory.The file is named factbook-timestamp.zip (db_name-timestamp.zip).To restore the database the file with the newest timestamp is taken.=Language Bindings=
==See also ==[[BaseX Standalone]], [[BaseX GUI]], [[Getting Started Guide]]If you want to communicate with the database server programmatically, we provide clients for various [[Advanced User Portal]][[Category:Beginner]][[Category:ServerClients|programming languages]].
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu