我正在尝试制作一个创建mysql用户和数据库的bash脚本,但是我找不到将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';"
如何用查询来提供mysql?
尝试这样:
echo "select 1" | mysql