Quick start
The quickest way to get started with YugabyteDB is to create a free Sandbox cluster in YugabyteDB Managed:
The first time you log in, YugabyteDB Managed provides a welcome experience with a 15 minute guided tutorial. Complete the steps in the Get Started tutorial to do the following:
- Connect to the database
- Load sample data and run queries
- Explore a sample application
If you aren't using the Get Started tutorial, use the following instructions to create a cluster, connect to your database, explore distributed SQL, and build an application.
Create your Sandbox cluster
The Sandbox cluster provides a fully functioning single node YugabyteDB cluster deployed to the region of your choice. The cluster is free forever and includes enough resources to explore the core features available for developing applications with YugabyteDB. No credit card information is required.
Sandbox cluster
YugabyteDB is a distributed database optimized for deployment across a cluster of servers. The Sandbox cluster has a single node and limited resources, suitable for running tutorials, Yugabyte University, and building sample applications. See Differences between Sandbox and Dedicated clusters for more information.
To evaluate YugabyteDB Managed for production use or conduct a proof-of-concept (POC), contact Yugabyte Support for trial credits.
To create your Sandbox cluster:
-
Click Create a Free cluster on the welcome screen, or click Add Cluster on the Clusters page to open the Create Cluster wizard.
-
Select Sandbox and click Choose.
-
Enter a name for the cluster, choose the cloud provider (AWS or GCP), and choose the region in which to deploy the cluster, then click Next.
-
Click Add Current IP Address. The IP address of your machine is added to the IP allow list. This allows you to connect to your sandbox cluster from applications and your desktop after it is created.
-
Click Next.
-
Click Download credentials. The default credentials are for a database user named "admin". You'll use these credentials when connecting to your YugabyteDB database.
-
Click Create Cluster.
YugabyteDB Managed bootstraps and provisions the cluster, and configures YugabyteDB. The process takes around 5 minutes. While you wait, you can optionally fill out a survey to customize your getting started experience.
When the cluster is ready, the cluster Overview is displayed. You now have a fully configured YugabyteDB cluster provisioned in YugabyteDB Managed.
Connect to the cluster
Use Cloud Shell to connect to your YugabyteDB Managed cluster from your browser, and interact with it using distributed SQL.
The shell has a one hour connection limit. If your session is idle for more than 5 minutes, it may disconnect. If your session expires, close your browser tab and connect again.
To connect to your cluster, do the following:
-
On the Clusters page, ensure your cluster is selected.
-
Click Connect to display the Connect to Cluster dialog.
-
Under Cloud Shell, click Launch Cloud Shell.
-
Enter the database name (
yugabyte
), the user name (admin
), select the YSQL API type, and click Confirm.Cloud Shell opens in a separate browser window. Cloud Shell can take up to 30 seconds to be ready.
Enter your DB password:
-
Enter the password for the admin user credentials that you saved when you created the cluster.
The shell prompt appears and is ready to use.
ysqlsh (11.2-YB-2.2.0.0-b0) SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off) Type "help" for help. yugabyte=>
The command line interface (CLI) being used is called ysqlsh. ysqlsh is the CLI for interacting with YugabyteDB using the PostgreSQL-compatible YSQL API. Cloud Shell also supports ycqlsh, a CLI for the YCQL API.
For information on other ways to connect to your cluster, refer to Connect to clusters.
Explore distributed SQL
When you connect to your cluster using Cloud Shell with the YSQL API (the default), the shell window incorporates a Quick Start Guide, with a series of pre-built queries for you to run. Follow the prompts to explore YugabyteDB in 5 minutes.
Build an application
Applications connect to and interact with YugabyteDB using API client libraries (also known as client drivers). This section shows how to connect applications to YugabyteDB Managed clusters using your favorite programming language.
Before you begin, you need the following:
- a cluster deployed in YugabyteDB Managed.
- the cluster CA certificate; YugabyteDB Managed uses TLS to secure connections to the database.
- your computer added to the cluster IP allow list.
Refer to Before you begin.
Choose your language
Choose the language you want to use to build your application.
The Java application connects to a YugabyteDB cluster using the topology-aware Yugabyte JDBC driver and performs basic SQL operations. Use the application as a template to get started with YugabyteDB in Java.
The application requires the following:
- Java Development Kit (JDK) 1.8, or later, is installed. JDK installers for Linux and macOS can be downloaded from Oracle, Adoptium (OpenJDK), or Azul Systems (OpenJDK). Homebrew users on macOS can install using
brew install openjdk
. - Apache Maven 3.3 or later.
To build and run the application, do the following:
-
Clone the sample application to your computer:
git clone https://github.com/YugabyteDB-Samples/yugabyte-simple-java-app.git && cd yugabyte-simple-java-app
-
Provide connection parameters.
(You can skip this step and use the defaults if your cluster is running locally and listening on 127.0.0.1:5433.)
The application needs to establish a connection to the YugabyteDB cluster. To do this:
-
Open the
app.properties
file located in the applicationsrc/main/resources/
folder. -
Set the following configuration parameters:
- host - the host name of your YugabyteDB cluster. For local clusters, use the default (127.0.0.1). For YugabyteDB Managed, select your cluster on the Clusters page, and click Settings. The host is displayed under Connection Parameters.
- port - the port number for the driver to use (the default YugabyteDB YSQL port is 5433).
- database - the name of the database you are connecting to (the default is
yugabyte
). - dbUser and dbPassword - the username and password for the YugabyteDB database. For local clusters, use the defaults (
yugabyte
). For YugabyteDB Managed, use the credentials in the credentials file you downloaded.
-
YugabyteDB Managed requires SSL connections, so you need to set the following additional parameters:
- sslMode - the SSL mode to use; use
verify-full
. - sslRootCert - the full path to the YugabyteDB Managed cluster CA certificate.
- sslMode - the SSL mode to use; use
-
Save the file.
-
-
Build the application.
$ mvn clean package
-
Start the application.
$ java -cp target/yugabyte-simple-java-app-1.0-SNAPSHOT.jar SampleApp
If you are running the application on a free or single node cluster, the driver displays a warning that the load balance failed and will fall back to a regular connection.
You should see output similar to the following:
>>>> Successfully connected to YugabyteDB!
>>>> Successfully created DemoAccount table.
>>>> Selecting accounts:
name = Jessica, age = 28, country = USA, balance = 10000
name = John, age = 28, country = Canada, balance = 9000
>>>> Transferred 800 between accounts.
>>>> Selecting accounts:
name = Jessica, age = 28, country = USA, balance = 9200
name = John, age = 28, country = Canada, balance = 9800
You have successfully executed a basic Java application that works with YugabyteDB.
The Go application connects to a YugabyteDB cluster using the Go PostgreSQL driver and performs basic SQL operations. Use the application as a template to get started with YugabyteDB in Go.
The application requires the following:
- Go (tested with version 1.17.6).
To build and run the application, do the following:
-
Clone the sample application to your computer:
git clone https://github.com/YugabyteDB-Samples/yugabyte-simple-go-app.git && cd yugabyte-simple-go-app
-
Provide connection parameters.
(You can skip this step and use the defaults if your cluster is running locally and listening on 127.0.0.1:5433.)
The application needs to establish a connection to the YugabyteDB cluster. To do this:
-
Open the
sample-app.go
file. -
Set the following configuration parameter constants:
- host - the host name of your YugabyteDB cluster. For local clusters, use the default (127.0.0.1). For YugabyteDB Managed, select your cluster on the Clusters page, and click Settings. The host is displayed under Connection Parameters.
- port - the port number for the driver to use (the default YugabyteDB YSQL port is 5433).
- dbName - the name of the database you are connecting to (the default is
yugabyte
). - dbUser and dbPassword - the username and password for the YugabyteDB database. For local clusters, use the defaults (
yugabyte
). For YugabyteDB Managed, use the credentials in the credentials file you downloaded.
-
YugabyteDB Managed requires SSL connections, so you need to set the following additional parameters:
- sslMode - the SSL mode to use; use
verify-full
. - sslRootCert - the full path to the YugabyteDB Managed cluster CA certificate.
- sslMode - the SSL mode to use; use
-
Save the file.
-
-
Initialize the
GO111MODULE
variable.$ export GO111MODULE=auto
-
Import the Go PostgreSQL driver.
$ go get github.com/lib/pq
-
Start the application.
$ go run sample-app.go
You should see output similar to the following:
>>>> Successfully connected to YugabyteDB!
>>>> Successfully created table DemoAccount.
>>>> Selecting accounts:
name = Jessica, age = 28, country = USA, balance = 10000
name = John, age = 28, country = Canada, balance = 9000
>>>> Transferred 800 between accounts.
>>>> Selecting accounts:
name = Jessica, age = 28, country = USA, balance = 9200
name = John, age = 28, country = Canada, balance = 9800
You have successfully executed a basic Go application that works with YugabyteDB.
The Python application connects to a YugabyteDB cluster using the Python psycopg2 PostgreSQL database adapter and performs basic SQL operations. Use the application as a template to get started with YugabyteDB in Python.
The application requires the following:
- Python 3.6 or later (Python 3.9.7 or later if running macOS on Apple silicon).
To build and run the application, do the following:
-
Clone the sample application to your computer:
git clone https://github.com/YugabyteDB-Samples/yugabyte-simple-python-app.git && cd yugabyte-simple-python-app
-
Provide connection parameters.
(You can skip this step and use the defaults if your cluster is running locally and listening on 127.0.0.1:5433.)
The application needs to establish a connection to the YugabyteDB cluster. To do this:
-
Open the
sample-app.py
file. -
Set the following configuration parameter constants:
- host - the host name of your YugabyteDB cluster. For local clusters, use the default (127.0.0.1). For YugabyteDB Managed, select your cluster on the Clusters page, and click Settings. The host is displayed under Connection Parameters.
- port - the port number for the driver to use (the default YugabyteDB YSQL port is 5433).
- dbName - the name of the database you are connecting to (the default is
yugabyte
). - dbUser and dbPassword - the username and password for the YugabyteDB database. For local clusters, use the defaults (
yugabyte
). For YugabyteDB Managed, use the credentials in the credentials file you downloaded.
-
YugabyteDB Managed requires SSL connections, so you need to set the following additional parameters:
- sslMode - the SSL mode to use; use
verify-full
. - sslRootCert - the full path to the YugabyteDB Managed cluster CA certificate.
- sslMode - the SSL mode to use; use
-
Save the file.
-
-
Install psycopg2 PostgreSQL database adapter.
$ pip3 install psycopg2-binary
-
Start the application.
$ python3 sample-app.py
You should see output similar to the following:
>>>> Successfully connected to YugabyteDB!
>>>> Successfully created table DemoAccount.
>>>> Selecting accounts:
name = Jessica, age = 28, country = USA, balance = 10000
name = John, age = 28, country = Canada, balance = 9000
>>>> Transferred 800 between accounts.
>>>> Selecting accounts:
name = Jessica, age = 28, country = USA, balance = 9200
name = John, age = 28, country = Canada, balance = 9800
You have successfully executed a basic Python application that works with YugabyteDB.
The Node.js application connects to a YugabyteDB cluster using the node-postgres driver and performs basic SQL operations. Use the application as a template to get started with YugabyteDB in Node.js.
The application requires the following:
- The latest version of Node.js.
To build and run the application, do the following:
-
Clone the sample application to your computer:
git clone https://github.com/YugabyteDB-Samples/yugabyte-simple-node-app.git && cd yugabyte-simple-node-app
-
Provide connection parameters.
(You can skip this step and use the defaults if your cluster is running locally and listening on 127.0.0.1:5433.)
The application needs to establish a connection to the YugabyteDB cluster. To do this:
-
Open the
sample-app.js
file. -
Set the following configuration parameter constants:
- host - the host name of your YugabyteDB cluster. For local clusters, use the default (127.0.0.1). For YugabyteDB Managed, select your cluster on the Clusters page, and click Settings. The host is displayed under Connection Parameters.
- port - the port number for the driver to use (the default YugabyteDB YSQL port is 5433).
- database - the name of the database you are connecting to (the default is
yugabyte
). - user and password - the username and password for the YugabyteDB database. For local clusters, use the defaults (
yugabyte
). For YugabyteDB Managed, use the credentials in the credentials file you downloaded.
-
YugabyteDB Managed requires SSL connections, so you need to set the following additional parameters:
- ssl - To enable
verify-ca
SSL mode, therejectUnauthorized
property is set totrue
to require root certificate chain validation; replacepath_to_your_root_certificate
with the full path to the YugabyteDB Managed cluster CA certificate.
- ssl - To enable
-
Save the file.
-
-
Install the node-postgres module.
npm install pg
-
Install the async utility:
npm install --save async
-
Start the application.
$ node sample-app.js
You should see output similar to the following:
>>>> Successfully connected to YugabyteDB!
>>>> Successfully created table DemoAccount.
>>>> Selecting accounts:
name = Jessica, age = 28, country = USA, balance = 10000
name = John, age = 28, country = Canada, balance = 9000
>>>> Transferred 800 between accounts.
>>>> Selecting accounts:
name = Jessica, age = 28, country = USA, balance = 9200
name = John, age = 28, country = Canada, balance = 9800
You have successfully executed a basic Node.js application that works with YugabyteDB.
The C application connects to a YugabyteDB cluster using the libpq driver and performs basic SQL operations. Use the application as a template to get started with YugabyteDB in C.
The application requires the following:
- 32-bit (x86) or 64-bit (x64) architecture machine. (Use Rosetta to build and run on Apple silicon.)
- gcc 4.1.2 or later, or clang 3.4 or later installed.
- OpenSSL 1.1.1 or later (used by libpq to establish secure SSL connections).
- libpq. Homebrew users on macOS can install using
brew install libpq
. You can download the PostgreSQL binaries and source from PostgreSQL Downloads.
To build and run the application, do the following:
-
Clone the sample application to your computer:
git clone https://github.com/YugabyteDB-Samples/yugabyte-simple-c-app.git && cd yugabyte-simple-c-app
-
Provide connection parameters.
(You can skip this step and use the defaults if your cluster is running locally and listening on 127.0.0.1:5433.)
The application needs to establish a connection to the YugabyteDB cluster. To do this:
-
Open the
sample-app.c
file. -
Set the following configuration-related macros:
- HOST - the host name of your YugabyteDB cluster. For local clusters, use the default (127.0.0.1). For YugabyteDB Managed, select your cluster on the Clusters page, and click Settings. The host is displayed under Connection Parameters.
- PORT - the port number for the driver to use (the default YugabyteDB YSQL port is 5433).
- DB_NAME - the name of the database you are connecting to (the default is
yugabyte
). - USER and PASSWORD - the username and password for the YugabyteDB database. For local clusters, use the defaults (
yugabyte
). For YugabyteDB Managed, use the credentials in the credentials file you downloaded.
-
YugabyteDB Managed requires SSL connections, so you need to set the following additional parameters:
- SSL_MODE - the SSL mode to use; use
verify-full
. - SSL_ROOT_CERT - the full path to the YugabyteDB Managed cluster CA certificate.
- SSL_MODE - the SSL mode to use; use
-
Save the file.
-
-
Build the application with gcc or clang.
gcc sample-app.c -o sample-app -I<path-to-libpq>/libpq/include -L<path-to-libpq>/libpq/lib -lpq
-
Replace
<path-to-libpq>
with the path to the libpq installation; for example,/usr/local/opt
. -
Start the application.
$ ./sample-app
You should see output similar to the following:
>>>> Successfully connected to YugabyteDB!
>>>> Successfully created table DemoAccount.
>>>> Selecting accounts:
name = Jessica, age = 28, country = USA, balance = 10000
name = John, age = 28, country = Canada, balance = 9000
>>>> Transferred 800 between accounts.
>>>> Selecting accounts:
name = Jessica, age = 28, country = USA, balance = 9200
name = John, age = 28, country = Canada, balance = 9800
You have successfully executed a basic C application that works with YugabyteDB.
The C++ application connects to a YugabyteDB cluster using the libpqxx driver and performs basic SQL operations. Use the application as a template to get started with YugabyteDB in C++.
The application requires the following:
- 32-bit (x86) or 64-bit (x64) architecture machine. (Use Rosetta to build and run on Apple silicon.)
- gcc 4.1.2 or later, or clang 3.4 or later installed.
- OpenSSL 1.1.1 or later (used by libpq and libpqxx to establish secure SSL connections).
- libpq. Homebrew users on macOS can install using
brew install libpq
. You can download the PostgreSQL binaries and source from PostgreSQL Downloads. - libpqxx. Homebrew users on macOS can install using
brew install libpqxx
. To build the driver yourself, refer to Building libpqxx.
To build and run the application, do the following:
-
Clone the sample application to your computer:
git clone https://github.com/YugabyteDB-Samples/yugabyte-simple-cpp-app.git && cd yugabyte-simple-cpp-app
-
Provide connection parameters.
(You can skip this step and use the defaults if your cluster is running locally and listening on 127.0.0.1:5433.)
The application needs to establish a connection to the YugabyteDB cluster. To do this:
-
Open the
sample-app.cpp
file. -
Set the following configuration-related constants:
- HOST - the host name of your YugabyteDB cluster. For local clusters, use the default (127.0.0.1). For YugabyteDB Managed, select your cluster on the Clusters page, and click Settings. The host is displayed under Connection Parameters.
- PORT - the port number for the driver to use (the default YugabyteDB YSQL port is 5433).
- DB_NAME - the name of the database you are connecting to (the default is
yugabyte
). - USER and PASSWORD - the username and password for the YugabyteDB database. For local clusters, use the defaults (
yugabyte
). For YugabyteDB Managed, use the credentials in the credentials file you downloaded.
-
YugabyteDB Managed requires SSL connections, so you need to set the following additional parameters:
- SSL_MODE - the SSL mode to use; use
verify-full
. - SSL_ROOT_CERT - the full path to the YugabyteDB Managed cluster CA certificate.
- SSL_MODE - the SSL mode to use; use
-
Save the file.
-
-
Build the application with gcc or clang.
g++ -std=c++17 sample-app.cpp -o sample-app -lpqxx -lpq \ -I<path-to-libpq>/libpq/include -I<path-to-libpqxx>/libpqxx/include \ -L<path-to-libpq>/libpq/lib -L<path-to-libpqxx>/libpqxx/lib
-
Replace
<path-to-libpq>
with the path to the libpq installation, and<path-to-libpqxx>
with the path to the libpqxx installation; for example,/usr/local/opt
. -
Start the application.
$ ./sample-app
You should see output similar to the following:
>>>> Successfully connected to YugabyteDB!
>>>> Successfully created table DemoAccount.
>>>> Selecting accounts:
name = Jessica, age = 28, country = USA, balance = 10000
name = John, age = 28, country = Canada, balance = 9000
>>>> Transferred 800 between accounts.
>>>> Selecting accounts:
name = Jessica, age = 28, country = USA, balance = 9200
name = John, age = 28, country = Canada, balance = 9800
You have successfully executed a basic C++ application that works with YugabyteDB.
The C# application connects to a YugabyteDB cluster using the Npgsql driver and performs basic SQL operations. Use the application as a template to get started with YugabyteDB in C#.
The application requires the following:
- .NET 6.0 SDK or later.
To build and run the application, do the following:
-
Clone the sample application to your computer:
git clone https://github.com/YugabyteDB-Samples/yugabyte-simple-csharp-app.git && cd yugabyte-simple-csharp-app
The
yugabyte-simple-csharp-app.csproj
file includes the following package reference to include the driver:<PackageReference Include="npgsql" Version="6.0.3" />
-
Provide connection parameters.
(You can skip this step and use the defaults if your cluster is running locally and listening on 127.0.0.1:5433.)
The application needs to establish a connection to the YugabyteDB cluster. To do this:
-
Open the
sample-app.cs
file. -
Set the following configuration-related parameters:
- urlBuilder.Host - the host name of your YugabyteDB cluster. For local clusters, use the default (127.0.0.1). For YugabyteDB Managed, select your cluster on the Clusters page, and click Settings. The host is displayed under Connection Parameters.
- urlBuilder.Port - the port number for the driver to use (the default YugabyteDB YSQL port is 5433).
- urlBuilder.Database - the name of the database you are connecting to (the default is
yugabyte
). - urlBuilder.Username and urlBuilder.Password - the username and password for the YugabyteDB database. For local clusters, use the defaults (
yugabyte
). For YugabyteDB Managed, use the credentials in the credentials file you downloaded.
-
YugabyteDB Managed requires SSL connections, so you need to set the following additional parameters:
- urlBuilder.SslMode - the SSL mode to use; use
SslMode.VerifyFull
. - urlBuilder.RootCertificate - the full path to the YugabyteDB Managed cluster CA certificate.
- urlBuilder.SslMode - the SSL mode to use; use
-
Save the file.
-
-
Build and run the application.
dotnet run
You should see output similar to the following:
>>>> Successfully connected to YugabyteDB!
>>>> Successfully created table DemoAccount.
>>>> Selecting accounts:
name = Jessica, age = 28, country = USA, balance = 10000
name = John, age = 28, country = Canada, balance = 9000
>>>> Transferred 800 between accounts.
>>>> Selecting accounts:
name = Jessica, age = 28, country = USA, balance = 9200
name = John, age = 28, country = Canada, balance = 9800
You have successfully executed a basic C# application that works with YugabyteDB.
The Ruby application connects to a YugabyteDB cluster using the Ruby Pg driver and performs basic SQL operations. Use the application as a template to get started with YugabyteDB in Ruby.
The application requires the following:
-
Ruby 3.1 or later.
-
OpenSSL 1.1.1 or later (used by libpq and pg to establish secure SSL connections).
-
libpq. Homebrew users on macOS can install using
brew install libpq
. You can download the PostgreSQL binaries and source from PostgreSQL Downloads. -
Ruby pg. To install Ruby pg, run the following command:
gem install pg -- --with-pg-include=<path-to-libpq>/libpq/include --with-pg-lib=<path-to-libpq>/libpq/lib
Replace
<path-to-libpq>
with the path to the libpq installation; for example,/usr/local/opt
.
To build and run the application, do the following:
-
Clone the sample application to your computer:
git clone https://github.com/YugabyteDB-Samples/yugabyte-simple-ruby-app.git && cd yugabyte-simple-ruby-app
-
Provide connection parameters.
(You can skip this step and use the defaults if your cluster is running locally and listening on 127.0.0.1:5433.)
The application needs to establish a connection to the YugabyteDB cluster. To do this:
-
Open the
sample-app.rb
file. -
Set the following configuration-related parameters:
- host - the host name of your YugabyteDB cluster. For local clusters, use the default (127.0.0.1). For YugabyteDB Managed, select your cluster on the Clusters page, and click Settings. The host is displayed under Connection Parameters.
- port - the port number for the driver to use (the default YugabyteDB YSQL port is 5433).
- dbname - the name of the database you are connecting to (the default is
yugabyte
). - user and password - the username and password for the YugabyteDB database. For local clusters, use the defaults (
yugabyte
). For YugabyteDB Managed, use the credentials in the credentials file you downloaded.
-
YugabyteDB Managed requires SSL connections, so you need to set the following additional parameters:
- sslmode - the SSL mode to use; use
verify-full
. - sslrootcert - the full path to the YugabyteDB Managed cluster CA certificate.
- sslmode - the SSL mode to use; use
-
Save the file.
-
-
Make the application file executable.
chmod +x sample-app.rb
-
Run the application.
$ ./sample-app.rb
You should see output similar to the following:
>>>> Successfully connected to YugabyteDB!
>>>> Successfully created table DemoAccount.
>>>> Selecting accounts:
name = Jessica, age = 28, country = USA, balance = 10000
name = John, age = 28, country = Canada, balance = 9000
>>>> Transferred 800 between accounts.
>>>> Selecting accounts:
name = Jessica, age = 28, country = USA, balance = 9200
name = John, age = 28, country = Canada, balance = 9800
You have successfully executed a basic Ruby application that works with YugabyteDB.
The Rust application connects to a YugabyteDB cluster using the Rust-Postgres driver and performs basic SQL operations. Use the application as a template to get started with YugabyteDB in Rust.
The application requires the following:
- Rust development environment. The sample application was created for Rust 1.58 but should work for earlier and later versions.
To build and run the application, do the following:
-
Clone the sample application to your computer:
git clone https://github.com/YugabyteDB-Samples/yugabyte-simple-rust-app.git && cd yugabyte-simple-rust-app
-
Provide connection parameters.
(You can skip this step and use the defaults if your cluster is running locally and listening on 127.0.0.1:5433.)
The application needs to establish a connection to the YugabyteDB cluster. To do this:
-
Open the
sample-app.rs
file in thesrc
directory. -
Set the following configuration-related constants:
- HOST - the host name of your YugabyteDB cluster. For local clusters, use the default (127.0.0.1). For YugabyteDB Managed, select your cluster on the Clusters page, and click Settings. The host is displayed under Connection Parameters.
- PORT - the port number for the driver to use (the default YugabyteDB YSQL port is 5433).
- DB_NAME - the name of the database you are connecting to (the default is
yugabyte
). - USER and PASSWORD - the username and password for the YugabyteDB database. For local clusters, use the defaults (
yugabyte
). For YugabyteDB Managed, use the credentials in the credentials file you downloaded.
-
YugabyteDB Managed requires SSL connections, so you need to set the following additional parameters:
- SSL_MODE - the SSL mode to use; use
SslMode::Require
. - SSL_ROOT_CERT - the full path to the YugabyteDB Managed cluster CA certificate.
- SSL_MODE - the SSL mode to use; use
-
Save the file.
-
-
Build and run the application.
$ cargo run
The driver is included in the dependencies list of the Cargo.toml
file and installed automatically the first time you run the application.
You should see output similar to the following:
>>>> Successfully connected to YugabyteDB!
>>>> Successfully created table DemoAccount.
>>>> Selecting accounts:
name = Jessica, age = 28, country = USA, balance = 10000
name = John, age = 28, country = Canada, balance = 9000
>>>> Transferred 800 between accounts.
>>>> Selecting accounts:
name = Jessica, age = 28, country = USA, balance = 9200
name = John, age = 28, country = Canada, balance = 9800
You have successfully executed a basic Rust application that works with YugabyteDB.
The PHP application connects to a YugabyteDB cluster using the php-pgsql driver and performs basic SQL operations. Use the application as a template to get started with YugabyteDB in PHP.
The application requires the following:
- PHP runtime. The sample application was created using PHP 8.1 but should work with earlier and later versions. Homebrew users on macOS can install PHP using
brew install php
. - php-pgsql driver.
- On macOS, Homebrew automatically installs the driver with
brew install php
. - Ubuntu users can install the driver using the
sudo apt-get install php-pgsql
command. - CentOS users can install the driver using the
sudo yum install php-pgsql
command.
- On macOS, Homebrew automatically installs the driver with
To build and run the application, do the following:
-
Clone the sample application to your computer:
git clone https://github.com/YugabyteDB-Samples/yugabyte-simple-php-app.git && cd yugabyte-simple-php-app
-
Provide connection parameters.
(You can skip this step and use the defaults if your cluster is running locally and listening on 127.0.0.1:5433.)
The application needs to establish a connection to the YugabyteDB cluster. To do this:
-
Open the
sample-app.php
file. -
Set the following configuration-related constants:
- HOST - the host name of your YugabyteDB cluster. For local clusters, use the default (127.0.0.1). For YugabyteDB Managed, select your cluster on the Clusters page, and click Settings. The host is displayed under Connection Parameters.
- PORT - the port number for the driver to use (the default YugabyteDB YSQL port is 5433).
- DB_NAME - the name of the database to connect to (the default is
yugabyte
). - USER and PASSWORD - the username and password for the YugabyteDB database. For local clusters, use the defaults (
yugabyte
). For YugabyteDB Managed, use the credentials in the credentials file you downloaded.
-
YugabyteDB Managed requires SSL connections, so you need to set the following additional parameters:
- SSL_MODE - the SSL mode to use; use
verify-full
. - SSL_ROOT_CERT - the full path to the YugabyteDB Managed cluster CA certificate.
- SSL_MODE - the SSL mode to use; use
-
Save the file.
-
-
Run the application.
$ php sample-app.php
You should see output similar to the following:
>>>> Successfully connected to YugabyteDB!
>>>> Successfully created table DemoAccount.
>>>> Selecting accounts:
name = Jessica, age = 28, country = USA, balance = 10000
name = John, age = 28, country = Canada, balance = 9000
>>>> Transferred 800 between accounts.
>>>> Selecting accounts:
name = Jessica, age = 28, country = USA, balance = 9200
name = John, age = 28, country = Canada, balance = 9800
You have successfully executed a basic PHP application that works with YugabyteDB.
Learn more
YugabyteDB Managed Documentation
Deploy clusters in YugabyteDB Managed