Skip to content

Instantly share code, notes, and snippets.

@aipi
Created February 7, 2017 16:03
Show Gist options
  • Save aipi/75a9c68c50931d0ee584ef883cad31e6 to your computer and use it in GitHub Desktop.
Save aipi/75a9c68c50931d0ee584ef883cad31e6 to your computer and use it in GitHub Desktop.
MySQL expect script to enter into database to avoid to insert sudo password and database password all the time.
#Instead use "mysql -u root -p" and put your sudo password and mysql password use this expect script:
#!/usr/bin/expect -f
#create an alias sql="/Users/macbookpro/Desktop/myProject/mysql-enter.sh"
#To know more about expect: http://www.admin-magazine.com/Articles/Automating-with-Expect-Scripts
spawn mysql -u root -p
expect {
"Password:" {
send "sudo_password\r"
}
"Enter password:" {
send "database_password\r"
}
}
expect {
"Password:" {
send "sudo_password\r"
}
"Enter password:" {
send "database_password\r"
}
}
interact
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment