title: Сan't automatically connect to RDS via the script on EC2?
body: <p>Im use terraform to create infrastr. in AWS. I'm using script on ec2 userdata, that connects to rds.But this script doesn`t work.</p>
  <pre><code>#! /bin/bash 
  yum update -y
  yum install -y httpd
  service httpd start
  usermod -a -G apache centos
  chown -R centos:apache /var/www
  yum install -y mysql php php-mysql
  systemctl enable httpd.service
  cd /var/www/html/
  echo &quot;[mysql]&quot; &gt; ~/.my.cnf
  echo &quot;user = myuser&quot; &gt;&gt; ~/.my.cnf
  echo &quot;password = passworddata&quot; &gt;&gt; ~/.my.cnf
  chmod 600 ~/.my.cnf   
  cd database/
  mysql -h db_server_address &lt; script.sql
  systemctl restart httpd.service
  </code></pre>
  <p>/var/log/cloud-init-output.log
  ERROR 1045 (28000): Access denied for user 'root'@'10.0.1.91' (using password: NO)</p>
  <p>Application cannot connect to the database because there is no schema created.
  But, when I do it manually into the instance everything works fine.I understand that script is not perfect, but what's the problem,why the script don`t take credentials from ~/.my.cnf?</p>