MySQL-command OK from commandline, notOK from bash-script
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
MySQL-command OK from commandline, notOK from bash-script
Hello,
when I execute the following line inside a bash script :
Code:
mysql -u MyUser -pMyPassword -h ip_databaseserver -D My-DB <<EOF
I get the output :
ERROR 1045 (28000) at line 2: Access denied for user 'MyUser'@'ip_databaseserver' (using password: YES)
When I execute this same command on commandline, there is no problem :
Code:
[root@server logging]# mysql -u MyUser -pMyPassword -h ip_databaseserver -D My-DB
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2692
Server version: 5.1.69 Source distribution
Copyright (c) 2000, 2011, 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>
Why can't I use this command inside a bash script ?
Last edited by jonaskellens; 05-13-2013 at 12:32 PM.
I maybe wrong, but my understanding of when you run a script, it is run in a subshell.
It's possible the subshell may not have the permission to access the database.
mysql> GRANT file ON MyDB.MyTable TO MyUser@'ip_databaseserver' IDENTIFIED BY 'MyPassword';
But I get :
ERROR 1144 (42000): Illegal GRANT/REVOKE command; please consult the manual to see which privileges can be used
It can be I have a problem with rights, which causes the error: ERROR 1045 (28000) at line 2: Access denied for user 'MyUser'@'ip_databaseserver' (using password: YES)
Last edited by jonaskellens; 05-14-2013 at 03:16 AM.
The CREATE USER, FILE, PROCESS, RELOAD, REPLICATION CLIENT, REPLICATION SLAVE, SHOW DATABASES, SHUTDOWN, and SUPER privileges are administrative and can only be granted globally.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.