I'm using script on ec2 user data, that connects to rds. But the script doesn`t work.

#! /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 "[mysql]" > ~/.my.cnf
echo "user = myuser" >> ~/.my.cnf
echo "password = passworddata" >> ~/.my.cnf
chmod 600 ~/.my.cnf   
cd database/
mysql -h db_server_address < script.sql
systemctl restart httpd.service

/var/log/cloud-init-output.log ERROR 1045 (28000): Access denied for user 'root'@'' (using password: NO)

When I do it manually on the instance everything works fine.I understand that the script is not perfect, but what's the problem, why the script don`t take credentials from ~/.my.cnf?

  • Does this help?
    – mustaccio
    Apr 26, 2022 at 16:05
  • @mustaccio - In my case it is standard Amazon linux. Apr 26, 2022 at 16:19
  • 10.x.x.x IP addresses are local to a given network. Are you coming from your machine? Or did you somehow connect into the cloud?
    – Rick James
    Apr 26, 2022 at 22:07
  • @RickJames - Im use terraform to create infrastr. in AWS.( I'm new on scripting, so have some problem.) Apr 27, 2022 at 14:49


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.