List:General Discussion« Previous MessageNext Message »
From:Johan De Meersman Date:October 11 2011 8:16am
Subject:Re: Why the same command have different results when it is in a bash script and when it is not?
View as plain text  
I don't have a direct answer for you, just some thoughts:
 * traditionally, "localhost" is thought of as an alias for 127.0.0.1
 * mysql however, tends to not interpret it like when connecting to the local server and
instead tries to connect to the socket
 * to force mysql client to connect over tcp/ip instead, use -h 127.0.0.1

It's possible that the execution environment of a script is subtly different and causes
the client to interpret it the other way, but I've no idea what the exact difference
would be.


----- Original Message -----
> From: "Peng Yu" <pengyu.ut@stripped>
> To: mysql@stripped
> Sent: Monday, 10 October, 2011 12:19:20 AM
> Subject: Why the same command have different results when it is in a bash script and
> when it is not?
> 
> Hi,
> 
> It is seems strange to me why the same command "mysql -hlocalhost
> -uxxx" when it is run from the command line, it will show an error.
> When it is run in a bash script, it runs fine. I guess this might be
> described somewhere, but I'm yet to find the answer. Does anybody
> know
> why this happens and how to make the command line version working?
> 
> ~$ mysql -hlocalhost -uxxx
> ERROR 1045 (28000): Access denied for user 'xxx'@'localhost' (using
> password: YES)
> ~$ cat `which mysqllocalhostxxx.sh `
> #!/usr/bin/env bash
> 
> mysql -hlocalhost -uxxx
> ~$  mysqllocalhostxxx.sh
> Welcome to the MySQL monitor.  Commands end with ; or \g.
> Your MySQL connection id is 101
> Server version: 5.5.9 Source distribution
> 
> Copyright (c) 2000, 2010, 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>
> 

-- 
Bier met grenadyn
Is als mosterd by den wyn
Sy die't drinkt, is eene kwezel
Hy die't drinkt, is ras een ezel
Thread
Why the same command have different results when it is in a bashscript and when it is not?Peng Yu10 Oct
  • Re: Why the same command have different results when it is in a bash script and when it is not?Rik Wasmus10 Oct
  • Re: Why the same command have different results when it is in a bash script and when it is not?Johan De Meersman11 Oct