Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following file: exp.exp



expect <<EOF
  log_user 0
  spawn mysql -h $db_host -u $db_user -p $db_pass 'create database $new_db_name'
  expect "password:"
  send "$db_pass\r"
  log_user 1
  expect eof

I make it executable by sudo chmod +x script/year_changer/create_db.exp, but if I try to execute it I get an error:

couldn't execute "mysql": no such file or directory
    while executing
"spawn mysql -h localhost  -u root -p rootpass  'create database db_2011'"
share|improve this question
I have to ask the obvious... Is the mysql client installed? – Joni Sep 12 '13 at 6:08
Yes definitely. sudo /usr/local/mysql/support-files/mysql.server restart Shutting down MySQL .. SUCCESS! Starting MySQL .... SUCCESS! – Andrey Yasinishyn Sep 12 '13 at 6:11
Is the mysql command in your $PATH when you run the script? – Barmar Sep 12 '13 at 6:12
@Barmar. Don't know really. How can I check it?? – Andrey Yasinishyn Sep 12 '13 at 6:13
What happens if you just type mysql from the shell instead of running the script? – Barmar Sep 12 '13 at 6:14
up vote 3 down vote accepted

Giving a command, without a full path, only really works without a path to the executable if its in your path variables - as per the mysql docs, you need to add PATH=${PATH}:/usr/local/mysql/bin to your path - in .bashrc for interactive shells or .bash_profiles for non interactive ones.

share|improve this answer

Make sure your mysql binary is in your $PATH variable. You can check this by executing

echo $PATH;

If you do not see the path to your mysql binary there, you'll have to modify the PATH variable and add the path to your mysql binary in the ~/.bash_profile or ~/.bash_rc file to make it available globally on login

You can alternatively use the full path to your mysql binary in your code. For example

spawn /usr/bin/mysql -h $db_host -u $db_user -p $db_pass 'create database $new_db_name'
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.