简体   繁体   中英

How to run a MYSQL script using a password from a command line?

When I try to connect to the remote MYSQL database through the command line this works fine despite the warning:

/sdzf => mysql -h db3  -u auser -ppassword DB_6 -A
Warning: Using a password on the command line interface can be insecure.

However, running a script does not work

/sdzf => mysql -h db3  -u auser -ppassword DB_6 -A< findrec.sql
Warning: Using a password on the command line interface can be insecure.
ERROR 1045 (28000) at line 1: Access denied for user 'auser'@'50.206.86.74'     
(using password: YES)

Despite my login statement included the database name I still needed to point to the database first in my SQL script when running in the batch mode:

USE DB_6;

If I login first using the same script "mysql -h db3 -u auser -ppassword DB_6 -A" then I do not need to point to the database in my SQL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM