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. Bash: How to Echo Tab and Newline While printing out result in bash, sometime we need to...
  4. PostgreSQL Database psql Command Line Query Sometime psql command line query can be useful when it...
  5. How to Remove MySQL Binary Log By default, MySQL 5.0 and above enables MySQL Binary Log....
  6. MySQL Quick Installation on FreeBSD Quick installation of MySQL Database on FreeBSD Server. Make sure...
  7. run sql/queries (postgres) within bash e.g. for things-to-buy in $(psql -d database-name -U username -c...
  8. Quick Screen Lock on Apple Mac OSX Locking your screen is critical when you are using your...
  9. Arrays in Bash Arrays is useful when it comes to data processing. Using...
  10. How to Change MySQL Data Directory in Linux Centos By default Linux CentOS or other Linux Distro installation, MySQL...

Leave a Reply