-1

I am trying to execute the SQL commands through the shell script.

I am able to connect through terminal.but when I am trying to connect using a shell script, It is showing access denied. How can we execute SQL scripts through the Linux shell script?

mysql -u "root" "-pspanidea" "mysql" < "sqlscript.sql"?
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Usman Maqbool
  • 3,351
  • 10
  • 31
  • 48
  • you need to connect to the database using a mysql user as opposed to a local machine account – newbie Jun 24 '19 at 10:33
  • It's possible you're using the wrong password for your DB. Check that you're using the correct user and password combination, and accessing the correct DB. The error you encountered implies that access was denied due to wrong password for the user 'root'. Also note that this is the DB password, not system user password for 'root' – Patrick W Jun 24 '19 at 10:48
  • 1
    Possible duplicate of [How to run SQL script in MySQL?](https://stackoverflow.com/questions/8940230/how-to-run-sql-script-in-mysql) – Patrick W Jun 24 '19 at 11:28
  • To not give the password through the `-p` option, and instead read it from a config file, see https://stackoverflow.com/a/9293090/11499871 – zwbetz Jun 24 '19 at 17:03

1 Answers1

-1

Is it because you have your -p switch inside your password quoted string? Try this:

mysql -u "root" -p "spanidea" "mysql" < "sqlscript.sql"
mark_b
  • 1,393
  • 10
  • 18
  • If I solved your issue can you mark my answer as 'accepted' (by clicking the green tick) please? Also for extra security, you can just provide the -p option without a password and it will ask you for the password (which is not shown) on the next line. – mark_b Jun 25 '19 at 14:45