Mysql DB create error on provision for domains with two dots

I was setting up a new site for the a client in the UK, so the domain ends .co.uk. I have set up all the .yml files as they should be with:

Local Dev: xxxxx.dev
Staging: staging.xxxxx.co.uk
Production: xxxxx.co.uk

Unfortunately this does not work when working locally as on Vagrant Provision you get an error as follows:

error creating database: MySQL does not support database with more than 1
dots
failed: [default] (item=xxxxx.co.uk) => {“failed”: true, “item”: “xxxxx.co.uk”}

Even though I have set Local to .dev its still trying to create a DB .co.uk

My wordpress_sites.yml looks like this:

wordpress_sites:
 xxxxx.co.uk:
    site_hosts:
      - canonical:xxxxxx.dev
        redirects:
          - www.xxxxxx.dev
    local_path: ../site # path targeting local Bedrock site directory (relative to Ansible root)
    admin_email: andrew@xxxxx.dev
    multisite:
      enabled: false
    ssl:
      enabled: false
      provider: self-signed
    cache:
      enabled: false
env:
      disable_wp_cron: true
      wp_home: http://xxxxx.dev
      wp_siteurl: http://xxxxx.dev/wp
      wp_env: development
      db_name: example_dev
      db_user: example_dbuser

I understand that it gets its name from

db_name - database name (default: <site name>_<env>

What version/commit of Trellis are you using?

The default db name is here: https://github.com/roots/trellis/blob/cbe647a26a95126a3cf7fd8ace7f1f2f0454adf0/group_vars/all/helpers.yml#L3

It converts dots to underscores to avoid this issue. Although it should be picking up your overridden db_name as example_dev.

1 Like

I’m using 0.9.8

I’m going to give it another go, with a fresh install…

OK this is interesting. I will now scan for any typos but getting the same error now on a full rebuild.

TASK [wordpress-setup : Create database of sites] ******************************
System info:
  Ansible 2.1.2.0; Vagrant 1.8.6; Darwin
  Trellis at "Update to WP-CLI 0.25.0 for WP 4.7 compat"
---------------------------------------------------
error creating database: MySQL does not support database with more than 1
dots
failed: [default] (item=xxxxx.co.uk) => {"failed": true, "item": "xxxxx.co.uk"}

NO MORE HOSTS LEFT *************************************************************

RUNNING HANDLER [common : restart memcached] ***********************************
changed: [default]

RUNNING HANDLER [common : reload php-fpm] **************************************
changed: [default]

RUNNING HANDLER [common : reload nginx] ****************************************
changed: [default]

RUNNING HANDLER [common : perform nginx reload] ********************************
changed: [default]

RUNNING HANDLER [fail2ban : restart fail2ban] **********************************
changed: [default]

RUNNING HANDLER [ferm : restart ferm] ******************************************
skipping: [default]

RUNNING HANDLER [ntp : restart ntp] ********************************************
changed: [default]

RUNNING HANDLER [sshd : restart ssh] *******************************************
changed: [default]
	to retry, use: --limit @/Users/flakyjake/Sites/xxxxxx.co.uk/trellis/dev.retry

PLAY RECAP *********************************************************************
default                    : ok=86   changed=68   unreachable=0    failed=1

Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.

My wordpress_sites.yml looks like this:

wordpress_sites:
 xxxxx.co.uk:
    site_hosts:
      - canonical: xxxxxx.dev
        redirects:
          - www.xxxxx.dev
    local_path: ../site # path targeting local Bedrock site directory (relative to Ansible root)
    admin_email: andrew@xxxxx.dev
    multisite:
      enabled: false
    ssl:
      enabled: false
      provider: self-signed
    cache:
      enabled: false
env:
      disable_wp_cron: true
      wp_home: http://xxxxx.dev
      wp_siteurl: http://xxxxx.dev/wp
      wp_env: development
      db_name: twodogs_dev
      db_user: twodogs

You could add a debugging task to see what’s going on:

- debug:
    var: site_env.db_name
  with_dict: "{{ wordpress_sites }}"

- name: Create database of sites
  mysql_db:
    name: "{{ site_env.db_name }}"
    state: present
    login_host: "{{ site_env.db_host }}"
    login_user: "{{ mysql_root_user }}"
    login_password: "{{ mysql_root_password }}"
  with_dict: "{{ wordpress_sites }}"
  when: site_uses_local_db and item.value.db_create | default(True)

Above this line: https://github.com/roots/trellis/blob/cbe647a26a95126a3cf7fd8ace7f1f2f0454adf0/roles/wordpress-setup/tasks/database.yml#L2

It will just output the database name so we can see what’s its actually using.

1 Like

Built a clean box, with previous parameters for new site dev, added in debug as requested. Does this help?

TASK [wordpress-setup : debug] *************************************************
ok: [default] => (item=xxxxx.co.uk) => {
    "item": "xxxxx.co.uk",
    "site_env.db_name": "xxxxxx_co_uk_{u'db_user': u'twodogs', u'disable_wp_cron': True, u'wp_siteurl': u'http://xxxxx.dev/wp', u'db_name': u'twodogs_dev', u'wp_env': u'development', u'wp_home': u'http://xxxxxx.dev'}"
}

TASK [wordpress-setup : Create database of sites] ******************************
System info:
  Ansible 2.1.2.0; Vagrant 1.8.6; Darwin
  Trellis at "Ensure there is always at least one PHP-FPM pool defined"
---------------------------------------------------
error creating database: MySQL does not support database with more than 1
dots
failed: [default] (item=xxxxx.co.uk) => {"failed": true, "item": "xxxxx.co.uk"}

wordpress_sites.yml

wordpress_sites:
  xxxxx.co.uk:
    site_hosts:
      - canonical: xxxxx.dev
        redirects:
          - www.xxxxx.dev
    local_path: ../site # path targeting local Bedrock site directory (relative to Ansible root)
    admin_email: andrew@xxxxx.dev
    multisite:
      enabled: false
    ssl:
      enabled: false
      provider: self-signed
    cache:
      enabled: false
env:
      disable_wp_cron: true
      wp_home: http://xxxxx.dev
      wp_siteurl: http://xxxxx.dev/wp
      wp_env: development
      db_name: twodogs_dev
      db_user: twodogs

Can you double check your wordpress_sites.yml formatting/indentation? Might just be a copy/paste thing, but env is not indented and is on same level as wordpress_sites. Make sure it’s indented properly at the same level as cache for example.

2 Likes

Those pesky indents!

Seems to be ok on a provision, i’ll try and do another to ensure its ok to see if i can re-create the original error, just to ensure it was my error.

Thanks anyway.

I’m having the same problem in Trellis 0.9.9

wordpress_sites:
  sub.domain.com:
    site_hosts:
      - canonical: sub.domain.dev
        redirects:
          - www.sub.domain.dev
    local_path: ../site # path targeting local Bedrock site directory (relative to Ansible root)
    admin_user: admin
    admin_email: admin@domain.com
    multisite:
      enabled: false
    ssl:
      enabled: false
      provider: self-signed
    cache:
      enabled: false
    env:
      db_name: sub.domain_development

I get this error:

System info:
  Ansible 2.1.2.0; Vagrant 1.8.6; Darwin
  Trellis 0.9.9: December 14th, 2016
---------------------------------------------------
error creating database: MySQL does not support database with more than 1
dots
failed: [default] (item=sub.domain.com) => {"failed": true, "item": "sub.domain.com"}

When I change db_name to:

      db_name: sub_domain_development

It provisions just fine!
Since you recommend naming your sites after their domain, this shouldn’t happen right?

That’s because you overwrote the default which does “underscore” the name: https://github.com/roots/trellis/blob/54d0010f0480cfc3829206083a01331aad3c65b9/group_vars/all/helpers.yml#L3

We could possible just underscore the name regardless here: https://github.com/roots/trellis/blob/cbe647a26a95126a3cf7fd8ace7f1f2f0454adf0/roles/wordpress-setup/tasks/database.yml#L4

If you removed that custom env, your db name would be sub_domain_com_development

2 Likes

Ah ok, thanks for clarifying that up!