bash – dealing with backtics ” ` ” in mysql statement

problem :

using backticks in bash for mysql statements. e.g. :

mysql -u username -h host -e “GRANT SELECT, LOCK TABLES ON `somedatabase`.* TO ‘someuser’@'somehost’;” -p<password with no space after parameter>

would get an error :

./scriptname: line 5: somedatabase: command not found

solution :

escape () the backticks ” ` ” surround “somedatabase”

mysql -u username -h host -e “GRANT SELECT, LOCK TABLES ON `somedatabase`.* TO ‘someuser’@'somehost’;” -p<password with no space after parameter>

Related posts:

  1. Reset MySQL Root Password Very often, once we didn’t log on to MySQL database...
  2. Create Root Privilege User on MySQL By default, MySQL root privileges user is “root”, I always...
  3. PostgreSQL Database psql Command Line Query Sometime psql command line query can be useful when it...
  4. How to Remove MySQL Binary Log By default, MySQL 5.0 and above enables MySQL Binary Log....
  5. MySQL Quick Installation on FreeBSD Quick installation of MySQL Database on FreeBSD Server. Make sure...
  6. run sql/queries (postgres) within bash e.g. for things-to-buy in $(psql -d database-name -U username -c...
  7. Quick Screen Lock on Apple Mac OSX Locking your screen is critical when you are using your...
  8. Arrays in Bash Arrays is useful when it comes to data processing. Using...
  9. How to Create User with useradd in FreeBSD You can invoke “adduser” command in FreeBSD in order to...
  10. screen in FreeBSD default to csh as suppose to bash (preferred) After changing bash shell to a new user using chsh,...

Leave a Reply