【发布时间】:2020-07-28 01:04:55
【问题描述】:
我正在尝试使用 bash 在 MySQL 表中插入一行,我已将以下脚本保存为 script.sh 并使用
运行bash script.sh
当脚本执行时,它成功且没有错误,但包含加密值的密码字段('$2b$10$FywS3Lc27let0C9VVvZYFOBYg.AwGA3VEtUs5YIAjjUWSSEI3Fqt2')存储为其他值,例如
b0.AwGA3VEtUs5YIAjjUWSSEI3Fqt2
而不是
$2b$10$FywS3Lc27let0C9VVvZYFOBYg.AwGA3VEtUs5YIAjjUWSSEI3Fqt2
我尝试使用 '' 和 "" 和 `` ,它们都不起作用
那么当有 $ 值时如何插入呢?
#!/bin/bash
mysql <<EOF
GRANT ALL PRIVILEGES ON *.* TO "test_mysql_user"@"localhost" IDENTIFIED BY "test_password";
FLUSH PRIVILEGES;
create database cricket;
use cricket;
//created tables
.....
.....
INSERT INTO admin
(
admin_id,
first_name,
middle_name,
last_name,
email_id,
password,
address,
city,
state,
zip_code,
country,
phone_code,
phone_number,
email_campaign)
VALUES
(
'root',
'root',
'root',
'root',
'root@gmail.com',
'$2b$10$FywS3Lc27let0C9VVvZYFOBYg.AwGA3VEtUs5YIAjjUWSSEI3Fqt2', //this field is the error , saved as someother value
'root',
'root',
'root',
'root',
'root',
'root',
'root',
'root');
EOF
【问题讨论】:
-
考虑使用 source 命令。这可能是一个快速的解决方法。