couldn't execute "mysql": no such file or directory, using autoexpect
Solution 1
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.
Solution 2
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'
Related videos on Youtube
Andrey Yasinishyn
Updated on September 18, 2022Comments
-
Andrey Yasinishyn over 1 year
I have the following file: exp.exp
#!/usr/bin/expect db_host='localhost' db_name='webui_dev' db_user='root' db_pass='rootpass' new_db_name='db_2011' 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 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'"
-
Joni over 10 yearsI have to ask the obvious... Is the mysql client installed?
-
Andrey Yasinishyn over 10 yearsYes definitely.
sudo /usr/local/mysql/support-files/mysql.server restart Shutting down MySQL .. SUCCESS! Starting MySQL .... SUCCESS!
-
Barmar over 10 yearsIs the
mysql
command in your$PATH
when you run the script? -
Andrey Yasinishyn over 10 years@Barmar. Don't know really. How can I check it??
-
Barmar over 10 yearsWhat happens if you just type
mysql
from the shell instead of running the script? -
Barmar over 10 years
echo $PATH
and see if it contains the directory where themysql
executable is installed? -
Thalys over 10 yearswhat does "which mysql" say? it might be that mysql is not in your path?
-
Andrey Yasinishyn over 10 yearsI'm sorry.. It's my mistake
mysql -bash: mysql: command not found
-
Barmar over 10 yearsBTW, since you're specifying the password on the command line, it won't prompt for the password, so you shouldn't
expect "password:"
. -
Andrey Yasinishyn over 10 years@Barmar. May you post you answer as an Answer?
-
Barmar over 10 yearsI didn't give an answer, I just asked questions, what should I post?
-
Andrey Yasinishyn over 10 years@Journeyman Geek It's blank, but you are right, it isn't in my path. By typing mysql I reseive an error
mysql -bash: mysql: command not found
. So I need to add it to the path. -
Thalys over 10 yearshm, which should normally give a full path, IIRC, is it even installed?
-
Andrey Yasinishyn over 10 yearsYes it is. I added mysql commans to my path and it works.
-
Andrey Yasinishyn over 10 years@Barmar. But your question was an clue to the solution. Thanks for help.
-