|
| 1 | +<!doctype html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="utf-8"> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 6 | + <title>Create and initialize a database — Scriptella</title> |
| 7 | + <meta name="description" content="Create an empty PostgreSQL or MariaDB database, then initialize its schema, load data, or migrate data with Scriptella."> |
| 8 | + <link rel="canonical" href="https://scriptella.org/howto/create-database.html"> |
| 9 | + <meta property="og:title" content="Create and initialize a database — Scriptella"> |
| 10 | + <meta property="og:description" content="Create an empty PostgreSQL or MariaDB database, then initialize its schema, load data, or migrate data with Scriptella."> |
| 11 | + <meta property="og:type" content="website"> |
| 12 | + <meta property="og:url" content="https://scriptella.org/howto/create-database.html"> |
| 13 | + <meta property="og:image" content="https://scriptella.org/images/scriptella-logo.svg"> |
| 14 | + <meta name="twitter:card" content="summary_large_image"> |
| 15 | + <meta name="twitter:title" content="Create and initialize a database — Scriptella"> |
| 16 | + <meta name="twitter:description" content="Create an empty PostgreSQL or MariaDB database, then initialize its schema, load data, or migrate data with Scriptella."> |
| 17 | + <link rel="icon" href="../favicon.ico" sizes="32x32"> |
| 18 | + <link rel="icon" type="image/png" href="../favicon-192.png" sizes="192x192"> |
| 19 | + <script src="../theme.js"></script> |
| 20 | + <link rel="stylesheet" href="../style.css"> |
| 21 | +</head> |
| 22 | +<body> |
| 23 | + <a class="skip-link" href="#main-content">Skip to content</a> |
| 24 | + <header class="site-header"> |
| 25 | + <nav class="primary-nav" aria-label="Primary navigation"> |
| 26 | + <div class="site-header__inner"> |
| 27 | + <a class="site-logo" href="../index.html" aria-label="Scriptella home"> |
| 28 | + <img class="site-logo__dark" src="../images/scriptella-logo.svg" width="190" height="38" alt="Scriptella"> |
| 29 | + <img class="site-logo__light" src="../images/scriptella-logo-light.svg" width="190" height="38" alt="Scriptella"> |
| 30 | + </a> |
| 31 | + <ul> |
| 32 | + <li><a href="../reference/index.html" aria-current="page">Documentation</a></li> |
| 33 | + <li><a href="../tutorial.html">Tutorial</a></li> |
| 34 | + <li><a href="../reference/drivers.html">Drivers</a></li> |
| 35 | + <li><a href="https://github.com/scriptella/scriptella-etl">GitHub</a></li> |
| 36 | + <li><a href="../download.html">Download</a></li> |
| 37 | + <li><a href="../support.html">Support</a></li> |
| 38 | + </ul> |
| 39 | + <div class="header-controls"> |
| 40 | + <div class="language-menu" data-language-menu><button class="language-toggle" type="button" data-language-toggle aria-expanded="false" aria-label="Language" title="Choose language"><svg aria-hidden="true" viewBox="0 0 24 24" focusable="false"><circle cx="12" cy="12" r="9"></circle><path d="M3 12h18M12 3a14 14 0 0 1 0 18M12 3a14 14 0 0 0 0 18"></path></svg><span class="visually-hidden">Choose language</span></button><div class="language-menu__dropdown" data-language-dropdown hidden><a href="https://github.com/scriptella/scriptella-etl/blob/master/README.zh-CN.md"><span>简体中文</span><small>README</small></a><a href="https://github.com/scriptella/scriptella-etl/blob/master/README.ko.md"><span>한국어</span><small>README</small></a><a href="https://github.com/scriptella/scriptella-etl/blob/master/README.de.md"><span>Deutsch</span><small>Geschichte</small></a></div></div> |
| 41 | + <button class="theme-toggle" type="button" data-theme-toggle data-theme-current="system" aria-label="Color theme: System. Switch to Light." title="System theme — switch to Light"><span class="visually-hidden">Change color theme</span></button> |
| 42 | + </div> |
| 43 | + </div> |
| 44 | + </nav> |
| 45 | + </header> |
| 46 | + |
| 47 | + <main id="main-content" class="page-shell docs-layout"> |
| 48 | + <nav class="docs-nav" aria-label="Documentation navigation"> |
| 49 | + <h2>Documentation</h2> |
| 50 | + <ul> |
| 51 | + <li><a href="../reference/index.html">Reference</a></li> |
| 52 | + <li><a href="../reference/drivers.html">Drivers</a></li> |
| 53 | + <li> |
| 54 | + <span class="docs-nav__group-label">How-tos</span> |
| 55 | + <ul> |
| 56 | + <li><a href="create-database.html" aria-current="page">Create and initialize a database</a></li> |
| 57 | + <li><a href="initialize-database.html">Initialize on application startup</a></li> |
| 58 | + <li><a href="migrate-from-ant.html">Migrate from the Ant SQL task</a></li> |
| 59 | + </ul> |
| 60 | + </li> |
| 61 | + <li><a href="../faq.html">FAQ</a></li> |
| 62 | + <li><a href="../docs/api/index.html">API documentation</a></li> |
| 63 | + <li><a href="../docs/dtd/index.html">DTD documentation</a></li> |
| 64 | + </ul> |
| 65 | + </nav> |
| 66 | + |
| 67 | + <article class="page-content"> |
| 68 | + <h1>Create and initialize a database</h1> |
| 69 | + <p class="lede">Start by creating an empty database with the database server's own tools. Once it exists, Scriptella can create schema objects, run SQL scripts, load initial data, import data, or migrate data from another database.</p> |
| 70 | + |
| 71 | + <section id="postgresql"> |
| 72 | + <h2>PostgreSQL</h2> |
| 73 | + <p>From a PostgreSQL SQL session, create a database with:</p> |
| 74 | + <pre><code class="language-sql">CREATE DATABASE myapp;</code></pre> |
| 75 | + <p>The standard command-line equivalent is:</p> |
| 76 | + <pre><code>createdb myapp</code></pre> |
| 77 | + <p>See the official PostgreSQL documentation for <a href="https://www.postgresql.org/docs/current/sql-createdatabase.html"><code>CREATE DATABASE</code></a> and <a href="https://www.postgresql.org/docs/current/app-createdb.html"><code>createdb</code></a>, including options for ownership, authentication, encoding, and permissions.</p> |
| 78 | + </section> |
| 79 | + |
| 80 | + <section id="mariadb"> |
| 81 | + <h2>MariaDB</h2> |
| 82 | + <p>From a MariaDB SQL session, create and select a database with:</p> |
| 83 | + <pre><code class="language-sql">CREATE DATABASE myapp; |
| 84 | +USE myapp;</code></pre> |
| 85 | + <p>See the official MariaDB <a href="https://mariadb.com/docs/server/reference/sql-statements/data-definition/create/create-database"><code>CREATE DATABASE</code> documentation</a> for details about privileges, character sets, and collation.</p> |
| 86 | + </section> |
| 87 | + |
| 88 | + <section id="initialize-with-scriptella"> |
| 89 | + <h2>Initialize it with Scriptella</h2> |
| 90 | + <p>Place the PostgreSQL JDBC driver in Scriptella's <code>lib</code> directory. Then save this example as <code>init.etl.xml</code>; it connects to the PostgreSQL database, creates a table, and inserts its first row:</p> |
| 91 | + <pre><code class="language-xml"><!DOCTYPE etl SYSTEM "http://scriptella.org/dtd/etl.dtd"> |
| 92 | +<etl> |
| 93 | + <connection |
| 94 | + driver="postgresql" |
| 95 | + url="jdbc:postgresql://localhost/myapp" |
| 96 | + user="postgres" |
| 97 | + password="password"/> |
| 98 | + |
| 99 | + <script> |
| 100 | + CREATE TABLE message ( |
| 101 | + id INTEGER PRIMARY KEY, |
| 102 | + text VARCHAR(100) |
| 103 | + ); |
| 104 | + |
| 105 | + INSERT INTO message VALUES (1, 'Hello from Scriptella'); |
| 106 | + </script> |
| 107 | +</etl></code></pre> |
| 108 | + <p>Run the ETL file with Scriptella:</p> |
| 109 | + <pre><code>scriptella init.etl.xml</code></pre> |
| 110 | + <p>This creates the table and inserts the first row. The same approach works with MariaDB and other JDBC databases by changing the connection URL and JDBC driver.</p> |
| 111 | + <p>For larger schemas, SQL can also be kept in separate files and included from the ETL file.</p> |
| 112 | + </section> |
| 113 | + |
| 114 | + <section id="whats-next"> |
| 115 | + <h2>What's next?</h2> |
| 116 | + <p>Scriptella is useful for organizing and running database scripts and data operations once the database exists. You can use it to:</p> |
| 117 | + <ul> |
| 118 | + <li>Create tables and other schema objects from SQL files.</li> |
| 119 | + <li>Populate initial data from SQL scripts.</li> |
| 120 | + <li>Import CSV, text, XML, and other <a href="../reference/drivers.html">supported sources</a>.</li> |
| 121 | + <li>Copy or migrate data from another database.</li> |
| 122 | + <li>Run a sequence of setup or migration scripts as one repeatable job.</li> |
| 123 | + </ul> |
| 124 | + <p>Follow the <a href="../tutorial.html">Scriptella tutorial</a> for runnable examples, then use the <a href="../reference/index.html">reference documentation</a> and <a href="../reference/drivers.html">driver and provider matrix</a> for configuration details.</p> |
| 125 | + </section> |
| 126 | + <aside class="github-prompt" aria-label="Support Scriptella"> |
| 127 | + <strong>Scriptella useful?</strong> |
| 128 | + <p>Star it on GitHub to help others discover it.</p> |
| 129 | + <a class="button button--github" href="https://github.com/scriptella/scriptella-etl">★ Star Scriptella on GitHub</a> |
| 130 | + </aside> |
| 131 | + </article> |
| 132 | + </main> |
| 133 | + |
| 134 | + <footer class="site-footer"> |
| 135 | + <div class="site-footer__inner"> |
| 136 | + <p><strong>Scriptella</strong> · Licensed under the Apache License, Version 2.0.</p> |
| 137 | + <p class="site-footer__credit">Built by <a class="pvrlabs-wordmark" href="https://pvrlabs.xyz" aria-label="PVR Labs"><span class="pvrlabs-wordmark__accent">PVR</span><span class="pvrlabs-wordmark__light">Labs</span></a></p> |
| 138 | + <nav aria-label="Footer navigation"> |
| 139 | + <ul> |
| 140 | + <li><a href="../reference/index.html">Documentation</a></li> |
| 141 | + <li><a href="../faq.html">FAQ</a></li> |
| 142 | + <li><a href="../docs/api/index.html">API Docs</a></li> |
| 143 | + <li><a href="../docs/dtd/index.html">DTD Reference</a></li> |
| 144 | + <li><a href="https://github.com/scriptella/scriptella-etl">GitHub</a></li> |
| 145 | + <li><a href="../changes.html">Change History</a></li> |
| 146 | + <li><a href="../license.html">License</a></li> |
| 147 | + <li><a href="../support.html">Support</a></li> |
| 148 | + </ul> |
| 149 | + </nav> |
| 150 | + </div> |
| 151 | + </footer> |
| 152 | + <!-- StatCounter: existing Scriptella project configuration --> |
| 153 | + <script> |
| 154 | + var sc_project = 10775960; |
| 155 | + var sc_invisible = 1; |
| 156 | + var sc_security = "53eaed1c"; |
| 157 | + </script> |
| 158 | + <script defer src="https://secure.statcounter.com/counter/counter.js"></script> |
| 159 | + <!-- End StatCounter --> |
| 160 | +</body> |
| 161 | +</html> |
0 commit comments