Installing mysql and creating a database on AL2 instance

31 Views Asked by At

I have a user data script that I am trying to use to install mysql and create a database on an AL2 instance using terraform. The installation looks great as I could verify using systemctl status mysql, however the creation of the database keeps throwing mysql: [Warning] Using a password on the command line interface can be insecure. ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) error when i inspected cloud-init logs. any ideas why this keeps happening and how i could resolve it? this is the user data script i am running

    user_data = <<-EOF
            #!/bin/bash
            #install mysql
            sudo rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
            wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
            sudo yum localinstall -y mysql57-community-release-el7-8.noarch.rpm
            sudo yum install -y mysql-community-server 

            #start & enable database
            sudo systemctl start mysqld
            sudo systemctl enable mysqld

            sudo mysql_secure_installation <<SCRIPT

                  y
                  Password123!
                  Password123!
                  y
                  y
                  y
                  y
                  SCRIPT
                  #create lyncdb database
                  sudo mysql -u root -pPassword123! -e "CREATE DATABASE lyncdb;"
                  sudo mysql -u root -pPassword123! -e "CREATE USER 'lyncdbuser'@'localhost' IDENTIFIED BY 'lyncPassw3rd!';"
                  sudo mysql -u root -pPassword123! -e "GRANT ALL PRIVILEGES ON lyncdb.* TO 'lyncdbuser'@'localhost';"           
            EOF

mysqld running status cloud init logs

0

There are 0 best solutions below