import paramiko # 创建SSH客户端对象 client = paramiko.SSHClient() # 自动添加主机名和密钥到本地的known_hosts文件 client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # 连接SSH服务器 client.connect('xxx.xxx.xxx.xxx', port=22, username='root', password='xxx') # 执行命令 stdin, stdout, stderr = client.exec_command("mysql -uroot -proot -hxxx -P3306 -e 'select * from test1.Student'") # 打印命令输出 str1 = stdout.read().decode() list1 = str1.split('\n')[1].split("\t") print(list1) # 关闭SSH连接 client.close()