A multi-tier application pattern might require a Wordpress database. This task creates a service that creates the Wordpress database inside the MySQL component.

About this task

Procedure

  1. Click New to create a new service.
  2. Under General enter the following values and click Next.

    Setting

    Value

    Name

    Wordpress Database

    Description

    Create Wordpress Database on MySQL

    Container

    MySQL

  3. Under Properties, click New and enter the following values.

    Setting

    Value

    Name

    dbpassword

    Description

    Root Password

    Type

    String

    Value

    gogo123

    Encryped

    Yes

    Overridable

    Yes

    Required

    No

    Computed

    No

  4. Click OK.
  5. Under Properties, click New again and enter the following values.

    Setting

    Value

    Name

    dbuser

    Description

    Root User

    Type

    String

    Value

    root

    Encryped

    No

    Overridable

    Yes

    Required

    No

    Computed

    No

  6. Click OK and click Next.
  7. Set the actions for this service in the Actions pane.
    1. In the Install row, select Bash as the Script Type.
    2. Still in the Install row, select Click Here to edit paste the following code into the Edit Script text box, and click OK.
      /usr/bin/mysql -e "CREATE DATABASE wordpress;" --user=$dbuser --password=$dbpassword
      /usr/bin/mysql -e "CREATE USER 'wordpressuser'@'%';" --user=$dbuser --password=$dbpassword
      /usr/bin/mysql -e "SET PASSWORD FOR 'wordpressuser'@'%'=PASSWORD('$dbpassword');" --user=$dbuser --password=$dbpassword
      /usr/bin/mysql -e "GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'%'IDENTIFIED BY '$dbpassword';" --user=$dbuser --password=$dbpassword
      /usr/bin/mysql -e "FLUSH PRIVILEGES;" --user=$dbuser --password=$dbpassword
  8. Click Next and click Finish.
  9. Select the new service and click Publish.