Changing the mysql bind-address within a script
Solution 1:
Adding to what's been said by @nonsenz, If you use puphpet.com's provisioning scripts then you can add a bash file to the /puphpet/files/startup-always folder and place all your commands in there. Anytime vagrant starts or reloads it will call the script:
mysql.sh
#!/bin/bash
echo "Updating mysql configs in /etc/mysql/my.cnf."
if [ 'sudo sed -i "s/.*bind-address.*/bind-address = 0.0.0.0/" /etc/mysql/my.cnf' ]; then
echo "Updated mysql bind address in /etc/mysql/my.cnf to 0.0.0.0 to allow external connections."
sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start
fi
Even Better (to enable cleaner output)
mysql.sh
#!/bin/bash
echo "Updating mysql configs in /etc/mysql/my.cnf."
sudo sed -i "s/.*bind-address.*/bind-address = 0.0.0.0/" /etc/mysql/my.cnf
echo "Updated mysql bind address in /etc/mysql/my.cnf to 0.0.0.0 to allow external connections."
sudo service mysql stop
sudo service mysql start
This enabled me to connect my IDE (PhpStorm) directly to the database on my guest machine via vagrant. Of course I gave the guest mysql user access to '%' and forwarded port 3306 on the guest to a port (3309) on the host. The access grant could also be done in this file as well.
Even Better'er (mysql execute add in)
mysql.sh
#!/bin/bash
echo "Updating mysql configs in /etc/mysql/my.cnf."
sudo sed -i "s/.*bind-address.*/bind-address = 0.0.0.0/" /etc/mysql/my.cnf
echo "Updated mysql bind address in /etc/mysql/my.cnf to 0.0.0.0 to allow external connections."
echo "Assigning mysql user user1 access on %."
sudo mysql -u user1 -pyourpassword --execute "GRANT ALL PRIVILEGES ON *.* TO 'user1'@'%' IDENTIFIED BY 'yourpassword' with GRANT OPTION; FLUSH PRIVILEGES;" yourdatabase
echo "Assigned mysql user user1 access on all hosts."
sudo service mysql stop
sudo service mysql start
Solution 2:
It looks like sed is the easiest way in this context (after a clean install):
sudo sed -i "s/.*bind-address.*/bind-address = 0.0.0.0/" /etc/mysql/my.cnf
Solution 3:
augtool -s set '/files/etc/mysql/my.cnf/target[ . = "mysqld"]/bind-address 0.0.0.0'
The Ubuntu package is called 'augeas-tools'
Solution 4:
Sounds like you're looking for Augeas.
The project page is here and some documentation and examples are here. MySQL is included on the stock lenses page but unfortunately the documentation links to a 404 page now.
There are also some examples of using it within Puppet here.