N
N
Nikolay2020-07-19 23:05:05
linux
Nikolay, 2020-07-19 23:05:05

Why doesn't authorization in MySql from bash script work?

Good day to all.
For the second hour I have been struggling with the problem, but there are no shifts.
There is a task to transfer the database and the sh script to the new server, which generates csv files for reports from this database.

On the server under Debian 10 + ispmanager + mariadb 10.3.22, the test123456 database was
created. The user test123456 was created for it with the same password test123456 ) at line 1: Access denied for user 'test123456'@'localhost' (using password: YES) The script itself


#!/bin/bash

DB_NAME="test123456"
MYSQL_USER="test123456"
MYSQL_PASSWORD="test123456"
DATE=`date +%s`
SQL="mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -D$DB_NAME -Bse"
OTHER_OUTPUT_DIR="/var/www/site.ru/data/www/site.ru/pictures/"

FILE="subscribereport.csv"
$SQL "select datetime, upper(trim(email)), upper(trim(name)), upper(trim(gender)), ip, promocode, lower(trim(utm_source)), lower(trim(utm_medium)), lower(trim(utm_campaign)), mobile_source from subscribe where email <> '' and email like '%@%.%' INTO OUTFILE '$TMP_DIR$FILE$DATE' FIELDS TERMINATED BY ';' ESCAPED BY \"\" ENCLOSED BY '\"';"

sed 's/NULL;/;/g' $TMP_DIR$FILE$DATE > $OUTPUT_DIR$FILE && sed -i '1s/^/\xef\xbb\xbf/' $OUTPUT_DIR$FILE

I created the user with the database through the panel, there have never been any problems, all the rights are there.
What could be the problem?
Already googled.... the brain explodes...

It is unlikely that it matters, but the script is launched from krone by command
chmod +x /var/www/site.ru/data/www/generate_report.sh; /var/www/site.ru/data/www/generate_report.sh >/var/www/site.ru/data/www/report.log 2>&1

Answer the question

In order to leave comments, you need to log in

5 answer(s)
O
Oleg Shulepov, 2020-07-20
@hoindex

Maybe they forgot something? :)

GRANT ALL ON test123456.* TO 'test123456'@'localhost';
FLUSH PRIVILEGES;

You can check like this:
SHOW GRANTS FOR 'test123456'@'localhost';

V
Victor Taran, 2020-07-20
@shambler81

there may be a special character in the password, then you will need to do -p'.....' and not just -p

E
Eugene, 2020-07-19
@Nc_Soft

you somehow strangely call sql from bash, try this

mysql --host=db_host --port=db_port --user=db_user --password=db_password --database=db_name --execute='sql here'

K
ky0, 2020-07-20
@ky0

Quotes some wild amount. It is likely that because of them. Try putting the request in a file and calling it in a script like this:
mysql %options% < sql_file
The second suspect is environment variables and, accordingly, the absence of absolute paths to files.
In general - when the script is called by hand from the console, what happens? Are there any mistakes?

C
CityCat4, 2020-07-20
@CityCat4

Russian (well, ok, English) in white - access denied. Either you specify the wrong password, or the wrong user.
You need to start with a manual entry under this user:
# mysql -u test123456 -p
and see the result. If logged in - try the commands in manual mode. It is also useful to enable general log - it really spoils great, but it shows bottlenecks.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question