In general, we want to enter the MySQL command mode always need to enter the following interactive password confirmation to enter the command line mode:
Zhanhailiang@linux-06bq:~> Mysql-u Sl-p
Enter Password:
In fact, we can use expect scripting, to pass to expect and Shell Interactive communication to achieve password-free login:
Zhanhailiang@linux-06bq:~> Cat mysql.sh
#!/usr/local/bin/expect
Spawn/usr/local/services/mysql/bin/mysql-u sl-p
Expect {
"Assword" {send "SLR"}
}
Interact
In fact, this script means "execute/usr/local/services/mysql/bin/mysql-u sl-p, wait for response, if matching assword, then send SL (that is, MySQL user login password), enter, simulate the user manual operation."
After you have written the mysql.sh script, give permission to enforce it, and then you can access the MySQL command line mode by executing mysql.sh to avoid the password.
zhanhailiang@linux-06bq:~> chmod +x mysql.sh
Zhanhailiang@linux-06bq:~>./mysql.sh
Spawn/usr/local/services/mysql/bin/mysql-u sl-p
Enter Password:
Welcome to the MySQL Monitor. Commands End With; or G.
Your MySQL Connection ID is 12912
Server Version:5.5.14-log MySQL Community Server (GPL)
Copyright (c), the Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark the Oracle Corporation and/or its
Affiliates. Names may trademarks of their respective
Owners.
Type ' help, ' or ' h ' for help. Type ' C ' to clear the current input statement.
Mysql>
Note: Expect has a large number of parameters and a wealth of application scenarios, interested students please check the man manual or other information.