Enter MySQL command mode with expect password

Source: Internet
Author: User
Tags command line manual mysql command line

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.