Answer the question
In order to leave comments, you need to log in
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
Answer the question
In order to leave comments, you need to log in
Maybe they forgot something? :)
GRANT ALL ON test123456.* TO 'test123456'@'localhost';
FLUSH PRIVILEGES;
SHOW GRANTS FOR 'test123456'@'localhost';
there may be a special character in the password, then you will need to do -p'.....' and not just -p
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'
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?
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 questionAsk a Question
731 491 924 answers to any question