Mysql 通过用户数据在 aws ec2 实例上安装

Mysql installation on aws ec2 instance through userdata

我将此脚本作为 ec2 实例中的用户数据来安装和设置 mysql。代码手动运行良好,但当作为用户数据提供给 ec2 实例时,它不会创建数据库或用户。

#!/bin/bash
sudo yum -y update
sudo yum -y install aspell aspell-en httpd24 mysql mysql-server php56 php56-cli php56-gd php56-intl php56-mbstring php56-mysqlnd php56-opcache php56-pdo php56-soap php56-xml php56-xmlrpc php56-pspell --skip-broken
sudo yum list installed
sudo /sbin/chkconfig httpd on
sudo /sbin/chkconfig mysqld on  
sudo /sbin/service httpd start
sudo /sbin/service mysqld start
sudo mysqladmin -u root password '123a'
sudo mysql -u root -p123a
CREATE DATABASE db;
CREATE USER '1234'@'localhost' IDENTIFIED BY '123a';
GRANT FILE ON *.* TO '1234'@'localhost';
FLUSH PRIVILEGES;

Mysql版本:5.7.28

你的授权命令不对,现在干脆就是没有密码

sudo mysql -u root -p123a -e  "CREATE DATABASE db DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;use db;create user 'db'@'localhost' identified by '123a';  grant all on testdb.* to 'db';GRANT ALL ON db.* TO ' db '@'localhost';GRANT ALL ON db.* TO ' db '@'%';FLUSH PRIVILEGES;"