Assume that you have installed the Database service and populated your data store with images for the type and versions of databases that you want, and that you can create and access a database.
This example shows you how to create and access a MySQL 5.5 database.
Determine which flavor to use for your database
When you create a database instance, you must specify a nova flavor. The flavor indicates various characteristics of the instance, such as RAM, root volume size, and so on. The default nova flavors are not sufficient to create database instances. You might need to create or obtain some new nova flavors that work for databases.
The first step is to list flavors by using the openstack flavor list command.
Here are the default flavors, although you may have additional custom flavors in your environment:
$ openstack flavor list
+-----+-----------+-------+------+-----------+-------+-----------+
| ID | Name | RAM | Disk | Ephemeral | VCPUs | Is_Public |
+-----+-----------+-------+------+-----------+-------+-----------+
| 1 | m1.tiny | 512 | 1 | 0 | 1 | True |
| 2 | m1.small | 2048 | 20 | 0 | 1 | True |
| 3 | m1.medium | 4096 | 40 | 0 | 2 | True |
| 4 | m1.large | 8192 | 80 | 0 | 4 | True |
| 5 | m1.xlarge | 16384 | 160 | 0 | 8 | True |
+-----+-----------+-------+------+-----------+-------+-----------+
Now take a look at the minimum requirements for various database instances:
Database | RAM (MB) | Disk (GB) | VCPUs |
---|---|---|---|
MySQL | 512 | 5 | 1 |
Cassandra | 2048 | 5 | 1 |
MongoDB | 1024 | 5 | 1 |
Redis | 512 | 5 | 1 |
MySQL example. This example creates a flavor that you can use with a MySQL database. This example has the following attributes:
mysql_minimum
6
.512
5
1
$ nova flavor-create mysql-minimum 6 512 5 1
+----+---------------+-----------+------+-----------+------+-------+-------------+-----------+
| ID | Name | Memory_MB | Disk | Ephemeral | Swap | VCPUs | RXTX_Factor | Is_Public |
+----+---------------+-----------+------+-----------+------+-------+-------------+-----------+
| 6 | mysql-minimum | 512 | 5 | 0 | | 1 | 1.0 | True |
+----+---------------+-----------+------+-----------+------+-------+-------------+-----------+
Create a database instance
This example creates a database instance with the following characteristics:
mysql_instance_1
6
In addition, this command specifies these options for the instance:
5
(5 GB).myDB
database.mysql
data store and the
mysql-5.5
datastore_version.userA
user with the password
password.$ trove create mysql_instance_1 6 --size 5 --databases myDB \
--users userA:password --datastore_version mysql-5.5 \
--datastore mysql
+-------------------+---------------------------------------------------------------------------------------t-----------------------------------------------------------------------------------------------------------------+
| Property | Value |
+-------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| created | 2014-05-29T21:26:21 |
| datastore | {u'version': u'mysql-5.5', u'type': u'mysql'} |
| datastore_version | mysql-5.5 |
| flavor | {u'id': u'6', u'links': [{u'href': u'https://controller:8779/v1.0/46d0bc4fc32e4b9e8520f8fc62199f58/flavors/6', u'rel': u'self'}, {u'href': u'https://controller:8779/flavors/6', u'rel': u'bookmark'}]} |
| id | 5599dad6-731e-44df-bb60-488da3da9cfe |
| name | mysql_instance_1 |
| status | BUILD |
| updated | 2014-05-29T21:26:21 |
| volume | {u'size': 5} |
+-------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Get the IP address of the database instance
First, use the trove list command to list all instances and their IDs:
$ trove list
+--------------------------------------+------------------+-----------+-------------------+--------+-----------+------+
| id | name | datastore | datastore_version | status | flavor_id | size |
+--------------------------------------+------------------+-----------+-------------------+--------+-----------+------+
| 5599dad6-731e-44df-bb60-488da3da9cfe | mysql_instance_1 | mysql | mysql-5.5 | BUILD | 6 | 5 |
+--------------------------------------+------------------+-----------+-------------------+--------+-----------+------+
This command returns the instance ID of your new instance.
You can now pass in the instance ID with the trove show command
to get the IP address of the instance. In this example, replace
INSTANCE_ID
with 5599dad6-731e-44df-bb60-488da3da9cfe
.
$ trove show INSTANCE_ID
+-------------------+--------------------------------------+
| Property | Value |
+-------------------+--------------------------------------+
| created | 2014-05-29T21:26:21 |
| datastore | mysql |
| datastore_version | mysql-5.5 |
| flavor | 6 |
| id | 5599dad6-731e-44df-bb60-488da3da9cfe |
| ip | 172.16.200.2 |
| name | mysql_instance_1 |
| status | BUILD |
| updated | 2014-05-29T21:26:54 |
| volume | 5 |
+-------------------+--------------------------------------+
This command returns the IP address of the database instance.
Access the new database
You can now access the new database you just created (myDB) by using
typical database access commands. In this MySQL example, replace
IP_ADDRESS
with 172.16.200.2
.
$ mysql -u userA -p password -h IP_ADDRESS myDB
Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.