Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Wed Apr 14, 2010 10:12 am 
Offline
Junior Member

Joined: Wed Sep 03, 2008 9:51 am
Posts: 25
This is definitely an edge case that I can account for in my StackScripts before calling mysql_create_database from the Bash Library provided by Linode, but I thought I'd pass the info along in case you wanted to run the same code or add comments to the function.

MySQL has some wierd naming rules when it comes to database names - one that seems to bite everyone is that it can't contain a dash. I have a UDF in my script that prompts the user for a db name. While I can add comments to steer them in the right direction, I can't do any form validation, so the next best thing is to run the UDF through 'tr' before handing it off to mysql_create_database, like so:
Code:
DB_NAME=$(echo ${DB_NAME} | tr '[:cntrl:][:punct:][:space:]' '_')


I know changing user data can be bad, but usually creating a db is the first step in a chain of events that will fail miserably if the db creation fails, so IMHO it's a necessary evil.

If you deem this as not a bug but a "tip", feel free to move this post to the proper forum.


Top
   
 Post subject:
PostPosted: Fri Apr 16, 2010 10:24 am 
Offline
Junior Member

Joined: Wed Sep 03, 2008 9:51 am
Posts: 25
In researching this a bit more, I discovered the problem lies in escaping - the mysql_create_database function doesn't escape the db name, which makes mysql very picky. I used this workaround, which escapes the name properly:
Code:
    /usr/bin/mysqladmin create -u root -p"${DB_PASSWORD}" "${DB_NAME}"


This way there is no changing of the user's data.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group