# Connect with Go

Use the Go SingleStore driver (`go-singlestore-driver`), a Go driver for the `database/sql` driver package, to connect Go applications to SingleStore databases. This driver includes features and improvements specific to SingleStore.

Refer to the [Go-SingleStore-Driver](https://github.com/singlestore-labs/go-singlestore-driver) GitHub repository for more information on supported features and enhancements.

## Prerequisites

* [Install](https://go.dev/doc/install) the latest version of Go.
* SingleStore 8.7 or later.
* (Optional) [Install](https://git-scm.com/install/linux) `git`.

## Install the Go SingleStore Driver

Install the `go-singlestore-driver` package using the Go CLI utility:

```shell
go get -u github.com/singlestore-labs/go-singlestore-driver/v2
```

## Configure the Connection to SingleStore

Use the following connection configuration parameters in the standard MySQL DSN (Data Source Name) or other applicable methods:

* `protocol`: Network transport type used to establish the database connection, which determines how the accompanying address is interpreted. Use the `tcp` protocol for connecting with SingleStore Helios.
* `hostname`: IP address or hostname of the SingleStore workspace. Specified when the protocol is `tcp`.

  Refer to [SingleStore Helios Endpoints](https://docs.singlestore.com/cloud/connect-to-singlestore/singlestore-helios-endpoints.md) to determine the endpoint (`host:port`) of your deployment.
* `port`: Port of the SingleStore workspace. The default is `3306`. Specified when the protocol is `tcp`.
* `username`: Username of the SingleStore database user.
* `password`: Password for the SingleStore database user.
* `database`: Name of the SingleStore database to connect with.
* `param=value`: (Optional) Additional connection parameters.

The driver supports the following DSN format:

```DSN
<username>:<password>@tcp(<hostname:port>)/<dbname>[?param=value]
```

For more information on the DSN and supported parameters, refer to [DSN (Data Source Name)](https://github.com/singlestore-labs/go-singlestore-driver#dsn-data-source-name).

## Example

The following example connects to a SingleStore database and performs basic CRUD operations.

1. Create a project folder and initialize the Go module.
   ```shell
   mkdir ssGo
   cd ssGo
   go mod init ssGo
   ```

2. Install the `go-singlestore-driver` package.
   ```shell
   go get -u github.com/singlestore-labs/go-singlestore-driver/v2
   ```

3. Create a **main.go** file and add the following code to this file. Update the connection configuration of your SingleStore database in the code.
   ```go
   package main

   import (
   	"database/sql"
   	"fmt"
   	"log"

   	_ "github.com/singlestore-labs/go-singlestore-driver/v2"
   )

   func main() {
   	// Connection settings
   	host := "svc-xxxx"
   	port := "3306"
   	user := "s2user"
   	password := "p455w1kd"
   	database := "demo"

   	// SingleStore DSN
   	dsn := fmt.Sprintf(
   		"%s:%s@tcp(%s:%s)/%s?parseTime=true",
   		user,
   		password,
   		host,
   		port,
   		database,
   	)

   	// Open connection using the SingleStore driver
   	db, err := sql.Open("singlestore", dsn)
   	if err != nil {
   		log.Fatal(err)
   	}
   	defer db.Close()

   	// Verify connection
   	if err := db.Ping(); err != nil {
   		log.Fatal(err)
   	}

   	fmt.Println("Connected to SingleStore")

   	// Create table
   	createTableSQL := `
   	CREATE TABLE IF NOT EXISTS users (
   		id BIGINT AUTO_INCREMENT PRIMARY KEY,
   		name VARCHAR(100),
   		email VARCHAR(255)
   	)
   	`

   	_, err = db.Exec(createTableSQL)
   	if err != nil {
   		log.Fatal(err)
   	}

   	fmt.Println("Table created")

   	// Insert rows
   	insertSQL := `
   	INSERT INTO users (name, email)
   	VALUES (?, ?)
   	`

   	_, err = db.Exec(insertSQL, "Alice", "alice@example.com")
   	if err != nil {
   		log.Fatal(err)
   	}

   	_, err = db.Exec(insertSQL, "Bob", "bob@example.com")
   	if err != nil {
   		log.Fatal(err)
   	}

   	fmt.Println("Rows inserted")

   	// Update a row
   	updateSQL := `
   	UPDATE users
   	SET email = ?
   	WHERE name = ?
   	`

   	result, err := db.Exec(updateSQL, "alice@newdomain.com", "Alice")
   	if err != nil {
   		log.Fatal(err)
   	}

   	rowsUpdated, _ := result.RowsAffected()
   	fmt.Printf("Rows updated: %d\n", rowsUpdated)

   	// Delete a row
   	deleteSQL := `
   	DELETE FROM users
   	WHERE name = ?
   	`

   	result, err = db.Exec(deleteSQL, "Bob")
   	if err != nil {
   		log.Fatal(err)
   	}

   	rowsDeleted, _ := result.RowsAffected()
   	fmt.Printf("Rows deleted: %d\n", rowsDeleted)

   	// Query remaining rows
   	rows, err := db.Query(`
   		SELECT id, name, email
   		FROM users
   	`)
   	if err != nil {
   		log.Fatal(err)
   	}
   	defer rows.Close()

   	fmt.Println("\nRemaining users:")

   	for rows.Next() {
   		var id int
   		var name string
   		var email string

   		if err := rows.Scan(&id, &name, &email); err != nil {
   			log.Fatal(err)
   		}

   		fmt.Printf("ID=%d Name=%s Email=%s\n", id, name, email)
   	}

   	if err := rows.Err(); err != nil {
   		log.Fatal(err)
   	}
   }

   ```

4. Run the application.
   ```shell
   go run main.go

   ```
   ```output

   Connected to SingleStore
   Table created
   Rows inserted
   Rows updated: 1
   Rows deleted: 1

   Remaining users:
   ID=1 Name=Alice Email=alice@newdomain.com
   ```

## References

* [Go-SingleStore-Driver](https://github.com/singlestore-labs/go-singlestore-driver) GitHub repository
* Additional examples:

  * [Getting started with SingleStore and Go](https://github.com/singlestore-labs/start-with-singlestore-go/)
  * [Getting started with SingleStore stored procedures and Go](https://github.com/singlestore-labs/start-with-singlestore-go-stored-procedure)

***

Modified at: June 16, 2026

Source: [/cloud/developer-resources/connect-with-application-development-tools/connect-with-go/](https://docs.singlestore.com/cloud/developer-resources/connect-with-application-development-tools/connect-with-go/)

(An index of the documentation is available at /llms.txt)
