我试图制作一个bash脚本来创建一个MysqL用户和数据库,但是我找不到一种方法来将sql提供给MysqL,我试着用这种格式:
MysqL < echo "query"
但是这不行,请看下面的例子:
MysqL --host=localhost --user=user --password=password < echo "CREATE USER 'testuser'@'localhost' IDENTIFIED BY 'jakdJxct8W'; CREATE DATABASE IF NOT EXISTS 'testuser_dev' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin; GRANT ALL PRIVILEGES ON 'testuser_dev' . * TO 'testuser'@'localhost'; CREATE DATABASE IF NOT EXISTS 'testuser_qa' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin; GRANT ALL PRIVILEGES ON 'testuser_qa' . * TO 'testuser'@'localhost';"
尝试这样:
echo "select 1" | MysqL