2017-02-14 463 views
0

我嘗試使用shell腳本如下修改MySQL的root用戶密碼shell腳本

#!/bin/bash 
mysql.server start 
mysql -u root << EOF 
    SET PASSWORD FOR [email protected]'localhost' = PASSWORD(‘admin’); 
EOF 

更改用戶密碼,但我得到以下錯誤: -

ERROR 1064 (42000) at line 1: 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 '‘admin’)' at line 1

不是set密碼時應的命令,如果用別的東西會像如果我使用「創建數據庫數據庫名稱」將會作品。

Update1:

如果我使用「管理員」或「管理員」而不是「管理員」,我得到了以下錯誤。

ERROR 1064 (42000) at line 1: 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 '「admin2」)' at line 1

Update2:

當使用-e標誌我有以下錯誤

./mysql.sh: line 3: syntax error near unexpected token (' ./mysql.sh: line 3: mysql -u root -padmin -e 「SET PASSWORD FOR [email protected]'localhost' = PASSWORD(‘admin2’);」'

+0

'「admin''你能在這些報價包裝?嘗試'「管理員」'或''admin''代替 – Gravy

+0

感謝回答,我認爲問題是由於編輯:) –

回答

1

用mysql -e代替:

#!/bin/bash 
mysql.server start 
mysql -u root -e "SET PASSWORD FOR [email protected]'localhost' = PASSWORD(‘admin’);" 
+0

我認爲問題是由於一些編輯,我使用其他編輯器寫相同的腳本和佛拉你和我的腳本既會工作。感謝回覆。 –