Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escaping hyphens with the mysql commandline tool

Tags:

mysql

Is there a way to escape a hyphen with the mysql commandline tool?

I basically need to do this:

mysql  -hlocalhost -uuser -puser information_schema -e  "CREATE DATABASE foo-bar"

Using mysqladmin is not an option due to the framework I'm within.

like image 219
joachim Avatar asked Oct 09 '10 08:10

joachim


2 Answers

"CREATE DATABASE \`foo-bar\`"

like image 83
Explosion Pills Avatar answered Oct 14 '22 08:10

Explosion Pills


Using backticks and using this way of piping the statement to mysql works:

echo 'create database `foo-bar2`' | mysql -uuser -ppassword

// John

like image 32
John P Avatar answered Oct 14 '22 06:10

John P