How to create a database and user for a mysql datastore on a trove instance

In the previous post I showed how to use a datastore called mysql, this is good for people who just want to get the datastore running and do all the database provisioning themselves. This post will show you how to setup a database and a user provisioned by trove.

After installing trove with the integration project, trovestack, we can create an instance with databases and users.

Assuming you have a trove instance running, here’s mine:

$ trove show my-inst
+-------------------------+--------------------------------------+
| Property | Value |
+-------------------------+--------------------------------------+
| created | 2017-05-31T17:14:08 |
| datastore | mysql |
| datastore_version | 5.6 |
| encrypted_rpc_messaging | True |
| flavor | 17 |
| id | 79a4cffc-92d3-4d52-a43c-490a7513841f |
| name | my-inst |
| region | RegionOne |
| server_id | 6405122e-08eb-4661-ad31-73701706435b |
| status | ACTIVE |
| tenant_id | dacf550217b9476a99cb2a5ae9713380 |
| updated | 2017-05-31T17:14:15 |
| volume | 4 |
| volume_id | 531c4c75-d833-4583-ad5f-5818a43b84f9 |
| volume_used | 0.11 |
+-------------------------+--------------------------------------+

You can now create a database by doing the following:

$ trove database-create 79a4cffc-92d3-4d52-a43c-490a7513841f my-db

Note: This command has no output

You can list databases on an instance to verify it was registered by doing the following:

$ trove database-list 79a4cffc-92d3-4d52-a43c-490a7513841f
+-------+
| Name  |
+-------+
| my-db |
+-------+

The same is true for users:

$ trove user-create 79a4cffc-92d3-4d52-a43c-490a7513841f my-user my-pass --databases my-db

Note: This command has no output

$ trove user-list 79a4cffc-92d3-4d52-a43c-490a7513841f
+---------+------+-----------+
| Name    | Host | Databases |
+---------+------+-----------+
| my-user | %    | my-db     |
+---------+------+-----------+

Now you have setup a database complete with a user, ready for use by the mysql datastore.

Use nova to get the ip for the host:

$ nova show my-inst
+--------------------------------------+---------------------------------------------------------------------------------+
| Property                             | Value                                                                           |
+--------------------------------------+---------------------------------------------------------------------------------+
| OS-DCF:diskConfig                    | MANUAL                                                                          |
| OS-EXT-AZ:availability_zone          | nova                                                                            |
| OS-EXT-SRV-ATTR:host                 | ubuntu                                                                          |
| OS-EXT-SRV-ATTR:hostname             | my-inst                                                                         |
| OS-EXT-SRV-ATTR:hypervisor_hostname  | ubuntu                                                                          |
| OS-EXT-SRV-ATTR:instance_name        | instance-00000004                                                               |
| OS-EXT-SRV-ATTR:kernel_id            |                                                                                 |
| OS-EXT-SRV-ATTR:launch_index         | 0                                                                               |
| OS-EXT-SRV-ATTR:ramdisk_id           |                                                                                 |
| OS-EXT-SRV-ATTR:reservation_id       | r-5en46upl                                                                      |
| OS-EXT-SRV-ATTR:root_device_name     | /dev/vda                                                                        |
| OS-EXT-SRV-ATTR:user_data            | -                                                                               |
| OS-EXT-STS:power_state               | 1                                                                               |
| OS-EXT-STS:task_state                | -                                                                               |
| OS-EXT-STS:vm_state                  | active                                                                          |
| OS-SRV-USG:launched_at               | 2017-05-31T17:14:20.000000                                                      |
| OS-SRV-USG:terminated_at             | -                                                                               |
| accessIPv4                           |                                                                                 |
| accessIPv6                           |                                                                                 |
| config_drive                         | True                                                                            |
| created                              | 2017-05-31T17:14:14Z                                                            |
| description                          | my-inst                                                                         |
| flavor                               | test.small-5 (17)                                                               |
| hostId                               | 40d0a91aa9100e69d39046509940b06a867bc7988158d358a44998d6                        |
| host_status                          | UP                                                                              |
| id                                   | 6405122e-08eb-4661-ad31-73701706435b                                            |
| image                                | ubuntu_mysql (b1bd8498-4c5f-42b8-925e-d9ba0f2bf906)                             |
| key_name                             | -                                                                               |
| locked                               | False                                                                           |
| metadata                             | {}                                                                              |
| name                                 | my-inst                                                                         |
| os-extended-volumes:volumes_attached | [{"id": "531c4c75-d833-4583-ad5f-5818a43b84f9", "delete_on_termination": true}] |
| progress                             | 0                                                                               |
| public network                       | 172.24.4.10                                                                     |
| security_groups                      | SecGroup_79a4cffc-92d3-4d52-a43c-490a7513841f                                   |
| status                               | ACTIVE                                                                          |
| tags                                 | []                                                                              |
| tenant_id                            | dacf550217b9476a99cb2a5ae9713380                                                |
| updated                              | 2017-05-31T17:14:20Z                                                            |
| user_id                              | 7fc47e259bb14dcdae0353cd6fc13ba2                                                |
+--------------------------------------+---------------------------------------------------------------------------------+

Use the ip for host argument (-h) and the user and passwords set for the user below:

$ mysql -u my-user -pmy-pass -h 172.24.4.10 -s
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql>

Leave a comment