1 回答

TA貢獻1836條經驗 獲得超5個贊
正如@Charles 在評論中提到的,
read() 將內容消耗到 EOF。這里沒有 EOF,因為 MySQL 仍然處于打開狀態。簡單的答案是不僅要刷新標準輸入,還要關閉它。
你不能這樣做,因為 MySQL 仍然是打開的,你的腳本會掛在那里。因此,如果您只想獲取數據庫,則將查詢傳遞給 MySQL 連接并且可以正常工作:)。
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy() )
ssh.connect(hostname='172.18.109.244', username='somuser',password='bgf')
print "Logged In to EMS"
cmd = 'mysql -h somehost.example.com -uroot -proot -e \'show databases;\''
stdin, stdout, stderr = ssh.exec_command(cmd)
# stdin.write("show databases;")
stdin.write('\n')
stdin.flush()
print stdout.read()
添加回答
舉報