expect一键登录mysql
?代碼如下:
?
#!/usr/bin/expect -f spawn mysql -u root -h localhost -p expect "Enter password: " send "appleyuchi\r\n" interact注意expect中的空格不能少
?
然后
chmod u+x mysqlz.sh
cp mysqlz.sh /usr/bin
chmod 777 /usr/bin/mysqlz.sh
.bashrc中加入:
alias mysqlz=/usr/bin/mysqlz.sh
最終效果(實現一鍵登錄,注意因為下面的Enter password:后面有個空格,所以上面的sh文件中的expect后面的password后面也要有個空格):
(python2.7) appleyuchi@ubuntu16:~$ mysqlz
spawn mysql -u root -h localhost?-p
Enter password:?
Welcome to the MySQL monitor.? Commands end with ; or \g.
Your MySQL connection id is 51
Server version: 5.7.21-0ubuntu0.16.04.1 (Ubuntu)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>?
?
?
總結
以上是生活随笔為你收集整理的expect一键登录mysql的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python建立数据库表格
- 下一篇: Cannot check for MyS