Changes

Jump to navigation Jump to search
2,386 bytes removed ,  11:15, 15 February 2021
no edit summary
This step by step tutorial is part of article belongs to the [[Getting Started]] Guide.It shows tells you how to run BaseX in client-server mode from a terminal. You can copy and paste all commands to get them running on your machine. After you finished this tutorial, you will be familiar with the basic administration of BaseX. Visit the [[Commands|commands section]] for a complete list of database commandscommand-line.
==Startup==
First, launch a '''==Server''' and '''Client''' instance of BaseX: double click on the '''BaseX Server/Client''' icons, or run the <code>basexserver</code> and <code>basexclient</code> scripts. [[Startup#BaseX Server|Follow this link]] for more information (or check out the additional [[Command-Line Options#BaseX Server|command-line options]]).==
==Create a The 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:
* To create a database you need an XML document, eRun one of the {{Code|basexserver}} or {{Code|basexserver.gbat}} scripts. [http://files.basex.org/xml/factbook.xml factbook.xml].* Save this document Add the {{Code|stop}} keyword to gracefully shut down the directory you are working inserver.* In If you have installed BaseX on ''Windows'', click on the client terminal'''BaseX HTTP Server (Start)''' icon, type in:<code>> which will start both the HTTP Server used for [[Commands#CREATE DBWeb Application|CREATE DBWeb Applications]] factbook factbookand the database server. With '''BaseX HTTP Server (Stop)''', you can shut down the server 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 950.83 ms.</pre> ; Where is the database stored?By default, databases Various [[Command-Line_Options#Server|command-line options]] are stored in the <code>BaseXData</code> directory, which is located in your home folderavailable to simplify batch processing.Depending on your The [[ConfigurationStart_Scripts|start script]], the location of your home folder variescan be adjusted for individual purposes (e.g. For example, on a Mac it's <code>/Users/John</code>, if your name the default memory limit is John. If you have used the Windows Installer, the directory will be named <code>data</code>, and reside in the application directorytoo restrictive).
==Execute a queryClient==The [[Commands#XQUERY|XQUERY]] command lets you run a query.* For example, this query returns all country nodes in the currently opened database.<code>> [[Commands#XQUERY|XQUERY]] //country</code>
* You can also run queries in filesDatabase clients are started similarly:<code>> [[Commands#RUN|RUN]] /Users/John/query.xq</code>
==Create a new database==* Run one of the {{Code|basexclient}} or {{Code|basexclient.bat}} scripts.Now we will create another database from * Execute the [httpfollowing command://files.basex{{Code|java -cp BaseX.jar org/xml/xmark.xml xmarkbasex.xml] documentBaseXClient}}* 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>> The initial passwort of the {{Code|admin}} user is {{Code|admin}}; it can be changed with the {{Code|[[Commands#CREATE DBPASSWORD|CREATE DBPASSWORD]] xmark xmark}} 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>> [[Commands#OPENStart_Scripts|OPENstart script]] xmark</code>.
* Now you can easily execute queries on your new database:<code>> [[Commands#XQUERY|XQUERY]] //people/person/name</code>=Introduction=
==Switch The BaseX command-line client provides similar features to the database==* You can explicitly query the factbook database with the <code>doc(...)</code> funtion, no matter what the current context is.<code>> [[Commands#XQUERYCommand-Line Client|XQUERYstandalone client]] doc. The major difference is that all commands will be executed by the BaseX server instance. As a consequence, paths/URIs to resources need to be resolvable by the server ("factbook"file contents will not be transfered to the server)//country</code>.
* Otherwise, to set factbook Username and password can also be specified as command-line option. To evaluate commands without entering the current contextconsole mode, execute you can use the following:<code>-c</code> option on the command line: <pre> [[Commands#OPEN|OPEN]] factbookbasexclient -V -Uadmin -Padmin -c "CREATE DB input <example/code>; XQUERY /"
* The following command lists all databases than can be opened by the currently logged Database 'input' created in users:13.85 ms.<codeexample/>> [[Commands#LIST|LIST]]Query:</code>
==Close or delete a database==Parsing: 0.18 ms* To [[Commands|close]] the current context database, please typeCompiling: 0.04 ms<code>Evaluating: 0.12 ms> [[Commands#CLOSE|CLOSE]]Printing: 0.07 ms</code>Total Time: 0.41 ms
* Use the [[Commands#DROP DB|DROP DB]] command to delete the xmark databaseHit(s):1 Item<code>Updated: 0 Items> Printed: 10 BytesRead Locking: local [[Commands#DROP DB|DROP DBinput]] xmark</code>Write Locking: none
==Create 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>> [[Commands#OPEN|OPEN]] factbook</code> * Now add the xmark.xml document: <code>> [[Commands#ADD|ADD]] xmark.xml</code> ==Delete a document==* Deleting a document from a collection is easy:<code>> [[Commands#DELETE|DELETE]] xmarkQuery "user" executed in 0.xml</code> Make sure that the collection, which contains the '''xmark.xml''' document, is opened. ==Delete a collection==Deleting a collection is the same as deleting a database41 ms* To delete the collection factbook, type:<code>> [[Commands#DROP DB|DROP DB]] factbook</codepre==Get server information==Several commands help to explore the state of a server. For a complete list, please visit the [[Commands]] Section. * To see all databases on the server, type:<code>> [[Commands#LIST|LIST]]</code> * To see the general information of the opened database, type:<code>> [[Commands#INFO|INFO]]</code> * To list all sessions that are managed by the server instance, type:<code>> [[Commands#SHOW USERS|SHOW USERS]]</code> ==Backup and restore==* To backup your database, type:<code>> [[Commands#CREATE BACKUP|CREATE BACKUP]] factbook</code> * To restore your database, type:<code>> [[Commands#RESTORE|RESTORE]] factbook</code> '''Where is the backup-file stored?'''
The backup-file is stored in the database directory.The file is named <code>factbook-timestamp.zip</code> (<code>db_name-timestamp.zip</code>).To restore the database the file with the newest timestamp is taken.=Language Bindings=
==See also ==[[Standalone Mode]], [[GUI]], [[Getting Started]]If you want to communicate with the database server programmatically, we provide clients for various [[Advanced Usage]][[Category:Beginner]][[Category:ServerClients|programming languages]].
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu