Missing `` around databasename in create_database()

Bug #1675220 reported by Heather Lanigan
18
This bug affects 3 people
Affects Status Importance Assigned to Milestone
OpenStack Percona Cluster Charm
Fix Released
High
James Page

Bug Description

$ juju status
Model Controller Cloud/Region Version
tom oil-os-subnets oil-os/RegionOne 2.2-beta1.1

App Version Status Scale Charm Store Rev OS Notes
mysql 5.6.21-25.8 active 1 percona-cluster jujucharms 250 ubuntu

Unit Workload Agent Machine Public address Ports Message
mysql/0* blocked executing 0 10.244.133.197 Unit is ready

Machine State DNS Inst id Series AZ Message
0 started 10.244.133.197 2641a568-51c8-450d-b034-a3a0091116bd xenial nova db-relation-changed hook failed

Relation Provides Consumes Type
cluster mysql mysql peer
db mysql remote-e03efa46926a41ae82f5e8ef0c1256f4 regular

Ran juju debug-hooks mysql/0:

root@juju-96017a-tom-0:/var/lib/juju/agents/unit-mysql-0/charm# hooks/db-relation-changed
Traceback (most recent call last):
  File "hooks/db-relation-changed", line 709, in <module>
    main()
  File "hooks/db-relation-changed", line 701, in main
    hooks.execute(sys.argv)
  File "/var/lib/juju/agents/unit-mysql-0/charm/hooks/charmhelpers/core/hookenv.py", line 731, in execute
    self._hooks[hook_name]()
  File "hooks/db-relation-changed", line 361, in db_changed
    password = db_helper.configure_db(addr, db_name, username, admin=admin)
  File "/var/lib/juju/agents/unit-mysql-0/charm/hooks/charmhelpers/contrib/database/mysql.py", line 313, in configure_db
    self.create_database(database)
  File "/var/lib/juju/agents/unit-mysql-0/charm/hooks/charmhelpers/contrib/database/mysql.py", line 90, in create_database
    .format(db_name))
  File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 226, in execute
    self.errorhandler(self, exc, value)
  File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
    raise errorvalue
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-e03efa46926a41ae82f5e8ef0c1256f4 CHARACTER SET UTF8' at line 1")
root@juju-96017a-tom-0:/var/lib/juju/agents/unit-mysql-0/charm#

Related branches

Revision history for this message
Drew Freiberger (afreiberger) wrote :

From duplicate bug lp#1688401:

strace -s 9000 hooks/db-relation-changed shows:

sendto(3, "1\0\0\0\3CREATE DATABASE hacluster-pxc CHARACTER SET UTF8", 53, 0, NULL, 0) = 53
recvfrom(3, "\262\0\0\1\377(\4#42000You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-pxc CHARACTER SET UTF8' at line 1",

Fix appears to be adding backticks`{}` around {} in following charmhelpers method call:

charmhelpers/contrib/database/mysql.py: cursor.execute("CREATE DATABASE {} CHARACTER SET UTF8"

Running cs:xenial/percona-cluster (#250) (17.02 charmers release)

tags: added: canonical-bootstack
Ante Karamatić (ivoks)
summary: - db-relation-changed hook failed: "You have an error in your SQL
- syntax;....
+ Missing `` around databasename in create_database()
James Page (james-page)
Changed in charm-percona-cluster:
status: New → Triaged
importance: Undecided → High
James Page (james-page)
Changed in charm-percona-cluster:
status: Triaged → In Progress
assignee: nobody → James Page (james-page)
milestone: none → 17.08
James Page (james-page)
tags: added: stable-backport
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to charm-percona-cluster (master)

Reviewed: https://review.openstack.org/464606
Committed: https://git.openstack.org/cgit/openstack/charm-percona-cluster/commit/?id=3facb32aff05f4b3048d1ac6c951e345aa80ecf5
Submitter: Jenkins
Branch: master

commit 3facb32aff05f4b3048d1ac6c951e345aa80ecf5
Author: James Page <email address hidden>
Date: Mon May 15 12:42:05 2017 +0200

    Correctly quote all MySQL syntax

    Resync charm-helpers to ensure that MySQL syntax is correctly
    quoted with single quotes, supporting use of the db-{admin} relation
    with services containing a dash.

    Change-Id: I859133263a8200e82e73d74837bcb91a18b3e0ff
    Closes-Bug: 1675220

Changed in charm-percona-cluster:
status: In Progress → Fix Committed
tags: added: adrastea
James Page (james-page)
Changed in charm-percona-cluster:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.