将用户添加到Mariadb的脚本
我正在尝试将用户添加到Mariadb中。男性用户使用航空公司作为密码,而女性则使用大陆作为密码,所有此信息均已通过CSV文件进行。
由于某种原因,我的脚本不起作用。这是脚本:
#!/bin/bash -p
FILENAME=mgarr048.csv
while IFS=: read -r username first last gender dob state municipality season continent elective f1 airline
do
(( gender == "m" )) || continue
mysql -e GRANT INSERT ON *.* to $username@'%' IDENTIFIED by $airline;
done
CSV标题
username,first,last,gender,dob,state,municipality,season,continent,elective,f1,airline
I am trying to add users into mariadb. Male users use an airline as password and females use a continent as a password all this info is taken form a csv file.
For some reason my script is not working. here is the script:
#!/bin/bash -p
FILENAME=mgarr048.csv
while IFS=: read -r username first last gender dob state municipality season continent elective f1 airline
do
(( gender == "m" )) || continue
mysql -e GRANT INSERT ON *.* to $username@'%' IDENTIFIED by $airline;
done
csv headers
username,first,last,gender,dob,state,municipality,season,continent,elective,f1,airline
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的脚本中,您没有任何地方告诉它阅读文件名。这样修改您的脚本:
ifs =;
更改为 ifs =,。 CSV中的C是“逗号”。编辑
由于我没有您的数据库进行测试,因此我将
echo
添加到mysql
line。将其删除以在您的系统上使用。如果收到mySQL
错误,它不是脚本,它与您的mySQL
命令和/或数据库有关。使用该数据集测试:
输出:
Nowhere in your script you tell it to read FILENAME. Modify your script like this:
IFS=;
toIFS=,
. C in CSV is "comma".EDIT
Since I do not have your database to test, I added
echo
to themysql
line. Remove it to use this on your system. If you get amysql
error, it is not the script, it is related to yourmysql
command and/or database.Tested with that data set:
Output: