Answers:
除了@nonsenz所说的以外,如果您使用puphpet.com的配置脚本,则可以将bash文件添加到/ puphpet / files / startup-always文件夹中,并将所有命令放在此处。每当无业游民启动或重新加载时,它将调用脚本:
#!/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
更好(以实现更清晰的输出)
#!/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
这使我可以通过流浪汉将IDE(PhpStorm)直接连接到来宾计算机上的数据库。当然,我授予来宾mysql用户访问'%'的权限,并将来宾上的端口3306转发到主机上的端口(3309)。访问权限也可以在此文件中完成。
更好(mysql执行加载项)
#!/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
augtool -s set '/files/etc/mysql/my.cnf/target[ . = "mysqld"]/bind-address 0.0.0.0'
Ubuntu软件包称为“ augeas-tools”
-s
是“自动保存所有更新”。 set
这是Augeas将为此采取的行动。 /files/etc/mysql/my.cnf
Augest将在哪个部分/文件上运行(加载所有/ etc)。 /target
是一个解码值的“数组”。 [ . = "mysqld"]
选择值为“ mysqld”的目标号码。 bind-address
是“ mysqld”部分中的bind-address字段,空格后0.0.0.0
的值是它将被设置为的值。
sudo
导致出现“对不起,您必须有tty”错误(仅通过从语句中删除'sudo'进行了修复),并且使用/etc/init.d/mysqld stop
和/etc/init.d/mysqld start
。这两个可能只是CentOS的怪癖,而不是脚本的错误。