2

I already know that in order to make Mysql understands a keyword as a column name we should add back ticks.

I am trying to execute this command from a shell script

echo "ALTER TABLE   partners.partners CHANGE COLUMN `name` `client_name` varchar(150) COLLATE utf8_unicode_ci DEFAULT NULL" | $MYSQL

Where $MYSQL is my databse connection command (which works fine for other commands).

What I am trying to do is rename the colomn named name to client_name but I have got this error :

 ./test_script.sh: 1: ./test_script.sh: name: not found

If I log to mysql console , execute the same thing , It works perfectly

Any one run into this problem before ?

1

1 Answer 1

2

Use single quotes to avoid interpretation of back-tick or ` which is otherwise used for command substitution:

$MYSQL -e 'ALTER TABLE partners.partners CHANGE COLUMN `name` `client_name` varchar(150) COLLATE utf8_unicode_ci DEFAULT NULL'
Sign up to request clarification or add additional context in comments.

1 Comment

That should've been my first reflex ! It is exactly that

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.