I would suggest trying:
apt-get -y install mysql-server mysql-client php5
The -y switch answers yes to all questions by default.
As far as the root password for MySQL goes, you may have to use a module like Pexpect to send the password, if you find yourself unable to pipe it through PySSH or cannot reliably determine when to send it.
updated answer:
I researched this a little and it seems you have a couple choices, both pretty involved on your part:
- Use Pexpect.
- Build a custom .deb that removes the password prompt from the "postinst" script
- Use apt-get and dpkg to unpack but not configure MySQL.
Option 1:
Rewrite your script to use Pexpect (this should be able to handle ncurses)
Option 2:
# get the original .deb:
apt-get -y --download-only -q install mysql-server
# need a tempdir for this
mkdir ~/tmp;cd ~/tmp
cp /var/cache/apt/mysql-version.deb .
ar -x mysql-version.deb
mkdir DEBIAN
tar xf control.tar.gz -C DEBIAN
vim DEBIAN/postinst
# edit the lines about prompting for rootpw in here and replace $rootpw with what you want,
# or however you choose to accomplish this
tar xf data.tar.gz -C .
dpkg-deb -b . mysql-server-version-noprompt.deb
And there's your new .deb. I haven't tested it, so YMMV.
Option 3:
# Skip postinst entirely
apt-get -q -y --download-only mysql-server
dpkg --unpack /var/cache/apt/mysql-server-version.deb
# instead of dpkg you can use dpkg-deb:
dpkg-deb -X /var/cache/apt/mysql-server-version.deb /
This will skip the postinstall entirely -- have a look at the script to see what it does, then repeat those steps.