All Projects → andreasf → cf-mysql-plugin

andreasf / cf-mysql-plugin

Licence: Apache-2.0 license
Cloud Foundry CLI MySQL Plugin

Programming Languages

go
31211 projects - #10 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to cf-mysql-plugin

paas-templates
Bosh, CFAR, CFCR and OSB services templates for use with COA (cf-ops-automation) framework
Stars: ✭ 16 (-54.29%)
Mutual labels:  cloudfoundry
openbrokerapi
A python package for the V2 CF Service Broker API
Stars: ✭ 32 (-8.57%)
Mutual labels:  cloudfoundry
PCC-Sample-App-PizzaStore
Example sample application which uses Pivotal Cloud Cache(PCC) as a service on Pivotal Cloud Foundry
Stars: ✭ 18 (-48.57%)
Mutual labels:  cloudfoundry
mssql-server-broker
Cloud Foundry service broker for Microsoft SQL Server
Stars: ✭ 13 (-62.86%)
Mutual labels:  cloudfoundry
cf-sample-app-spring
Introduction to Cloud Foundry app deployment and management concepts.
Stars: ✭ 30 (-14.29%)
Mutual labels:  cloudfoundry
cf-swagger
Collection of Swagger descriptions and applications for CloudFoundry BOSH
Stars: ✭ 22 (-37.14%)
Mutual labels:  cloudfoundry
cf-abacus
CF usage metering and aggregation
Stars: ✭ 100 (+185.71%)
Mutual labels:  cloudfoundry
eirini-release
Helm release for Project Eirini
Stars: ✭ 37 (+5.71%)
Mutual labels:  cloudfoundry
cf-tools
Useful shell scripts for Cloud Foundry API v2
Stars: ✭ 22 (-37.14%)
Mutual labels:  cloudfoundry
routing-release
This is the BOSH release for cloud foundry routers
Stars: ✭ 36 (+2.86%)
Mutual labels:  cloudfoundry
antifreeze
Cloud Foundry CLI plugin to detect if an app doesn't match the manifest
Stars: ✭ 21 (-40%)
Mutual labels:  cloudfoundry
credhub
CredHub centralizes and secures credential generation, storage, lifecycle management, and access
Stars: ✭ 203 (+480%)
Mutual labels:  cloudfoundry
spring-cloud-app-broker
Spring Cloud project for implementing service brokers that conform to the Open Server Broker API specification
Stars: ✭ 26 (-25.71%)
Mutual labels:  cloudfoundry
cf-python-client
Small cloudfoundry client implemented in python
Stars: ✭ 50 (+42.86%)
Mutual labels:  cloudfoundry
monarch
App-level Chaos Engineering
Stars: ✭ 26 (-25.71%)
Mutual labels:  cloudfoundry
bbr-pcf-pipeline-tasks
Collection of Concourse tasks for backing up a Tanzu Application Service (TAS) installation using BOSH Backup and Restore (BBR)
Stars: ✭ 39 (+11.43%)
Mutual labels:  cloudfoundry
credhub-cli
CredHub CLI provides a command line interface to interact with CredHub servers
Stars: ✭ 38 (+8.57%)
Mutual labels:  cloudfoundry
akka-react-cloudant
A Soccer Dashboard created by scraping EPL website using Akka backend and ReactJS frontend and IBM Cloudant for object storage. IBM Cloud Foundry is used to host both frontend and backend app.
Stars: ✭ 21 (-40%)
Mutual labels:  cloudfoundry
terraform-oci-cf-install
Terraform configurations for bootstrapping a CloudFoundry environment on Oracle Cloud Infrastructure
Stars: ✭ 15 (-57.14%)
Mutual labels:  cloudfoundry
heroku-buildpack-deno
Heroku Buildpack for Deno
Stars: ✭ 72 (+105.71%)
Mutual labels:  cloudfoundry

Cloud Foundry CLI MySQL Plugin

Build Status License

cf-mysql-plugin makes it easy to connect the mysql command line client to any MySQL-compatible database used by Cloud Foundry apps. Use it to

  • inspect databases for debugging purposes
  • manually adjust schema or contents in development environments
  • dump and restore databases

Contents

Usage

$ cf mysql -h
NAME:
   mysql - Connect to a MySQL database service

USAGE:
   Open a mysql client to a database:
   cf mysql <service-name> [mysql args...]


$ cf mysqldump -h
NAME:
   mysqldump - Dump a MySQL database

USAGE:
   Dumping all tables in a database:
   cf mysqldump <service-name> [mysqldump args...]

   Dumping specific tables in a database:
   cf mysqldump <service-name> [tables...] [mysqldump args...]

Connecting to a database

Passing the name of a database service will open a MySQL client:

$ cf mysql my-db
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 1377314
Server version: 5.5.46-log MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [ad_67fd2577d50deb5]> 

Piping queries or dumps into mysql

The mysql child process inherits standard input, output and error. Piping content in and out of cf mysql works just like it does with plain mysql:

$ cat database-dump.sql | cf mysql my-db

Passing arguments to mysql

Any parameters after the database name are added to the mysql invocation:

$ echo "select 1 as foo, 2 as bar;" | cf mysql my-db --xml
<?xml version="1.0"?>

<resultset statement="select 1 as foo, 2 as bar" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <row>
        <field name="foo">1</field>
        <field name="bar">2</field>
  </row>
</resultset>

Dumping a database

Running cf mysqldump with a database name will dump the whole database:

$ cf mysqldump my-db --single-transaction > dump.sql

Dumping individual tables

Passing table names in addition to the database name will just dump those tables:

$ cf mysqldump my-db table1 table2 --single-transaction > two-tables.sql

Removing service keys

The plugin creates a service key called 'cf-mysql' for each service instance a user connects to. The keys are reused when available and never deleted. Keys need to be removed manually before their service instances can be removed:

$ cf delete-service -f somedb
Deleting service somedb in org afleig-org / space acceptance as [email protected]...
FAILED
Cannot delete service instance. Service keys, bindings, and shares must first be deleted.

Deleting the service failed. The CLI hints at service keys and app bindings that might still exist.

$ cf service-keys somedb
Getting keys for service instance somedb as [email protected]...

name
cf-mysql

A key called 'cf-mysql' is found for the service instance 'somedb', because we have used the plugin with 'somedb' earlier. After removing the key, the service instance can be deleted:

$ cf delete-service-key -f somedb cf-mysql
Deleting key cf-mysql for service instance somedb as [email protected]...
OK

$ cf delete-service -f somedb
Deleting service somedb in org afleig-org / space acceptance as [email protected]...
OK

This behavior might change in the future as it's not optimal to leave a key around.

Installing and uninstalling

The easiest way is to install from the repository:

$ cf install-plugin -r "CF-Community" mysql-plugin

You can also download a binary release or build yourself by running go build. Then, install the plugin with

$ cf install-plugin /path/to/cf-mysql-plugin

The plugin can be uninstalled with:

$ cf uninstall-plugin mysql

Building

# download dependencies
go get -v -t ./...
go get github.com/onsi/ginkgo
go get github.com/onsi/gomega
go install github.com/onsi/ginkgo/ginkgo

# run tests and build
ginkgo -r
go build

Details

Obtaining credentials

cf-mysql-plugin creates a service key called 'cf-mysql' to obtain credentials. It no longer retrieves credentials from application environment variables, because with the introduction of CredHub, service brokers can decide to return a CredHub reference instead.

The service key is currently not deleted after closing the connection. It can be deleted by running:

cf delete-service-key service-instance-name cf-mysql

A started application instance is still required in the current space for setting up an SSH tunnel. If you don't have an app running, try the following to start an nginx app:

TEMP_DIR=`mktemp -d`
pushd $TEMP_DIR
touch Staticfile
cf push static-app -m 128M --no-route
popd
rm -r $TEMP_DIR
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].