我是新來的Perl,並試圖在RHEL框中編寫腳本,該腳本會自動配置我們在主機上創建的新站點的vanilla DB。我已經有連接語句工作,我能夠連接並從腳本中創建一個數據庫(使用$ dbh-> do(qq(CREATE DATABASE $ dbcreate));這是最好的方式???),但我有一對夫婦,我一直無法弄清楚如何讓他們工作。執行mysql命令的Perl腳本?
這些是我有問題的mysql命令。有什麼建議麼?謝謝!
$dbh = DBI->connect("DBI:mysql:$db:$host", $user, $pass);
$dbh->do(qq(CREATE DATABASE $dbcreate));
$dbh->do(qq(GRANT SELECT , INSERT , UPDATE , DELETE , CREATE , DROP , INDEX , ALTER , CREATE TEMPORARY TABLES , CREATE VIEW , SHOW VIEW , CREATE ROUTINE, ALTER ROUTINE, EXECUTE ON `$dbcreate` . * TO 'moodle'@'%'`));
$dbh->do(qq(FLUSH PRIVILEGES));
$dbh->do(qq($dbcreate < MySQL_pristine.sql));
$dbh->do(qq(USE $dbcreate));
$dbh->do(qq(UPDATE md1_label SET content = REPLACE(content, "pristine", "$dbcreate")));
$dbh->do(qq(UPDATE md1_label SET contents = REPLACE(contents, "pristine", "$dbcreate")));
$dbh->do(qq(UPDATE md1_label SET questiontext = REPLACE(questiontext, "pristine", "$dbcreate")));
DBD::mysql::db do failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'GRANT SELECT , INSERT , UPDATE , DELETE , CREATE , DROP , INDEX ,�' at line 1 at create-auto-db.pl line 52.
DBD::mysql::db do failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'test3 < MySQL_pristine.sql' at line 1 at create-auto-db.pl line 54.
DBD::mysql::db do failed: Table 'test3.md1_label' doesn't exist at create-auto-db.pl line 56.
DBD::mysql::db do failed: Table 'test3.md1_label' doesn't exist at create-auto-db.pl line 57.
DBD::mysql::db do failed: Table 'test3.md1_label' doesn't exist at create-auto-db.pl line 58.
如果你使用的是DBI,你爲什麼還試圖與mysql shell交互工作?你的問題的前半部分涉及Perl,後半部分涉及將文件重定向到命令行工具'mysql'。你的示例代碼中沒有Perl。此外,你還沒有解釋你有什麼問題。我們應該猜測嗎? – DavidO
所有這些語句都可以在'DBI'中正常工作,並且可以從'$ dbh-> do()'執行。如果您收到錯誤消息,請將它們發佈,然後再添加一些Perl。您發佈的單個聲明中存在一些風險,但沒有任何我們可以在沒有任何上下文的情況下提供幫助的風險。一個可能的問題是,如果你錯誤地引用了字符串(即用'qq {}'而不是'q {}'),則可能會插入'@'。 –
@morungos我編輯了我的帖子,包括我試過的代碼以及下面的錯誤。我認爲你對@符號是正確的。 – Brandon