Mysqldump not working in jenkins execute shell [closed] - mysql

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I have a shell script that is running as a cron job, which creates a database dump for backup purposes. When I tried doing the same in a Jenkins execute shell, the following line seems to be giving errors:
mysqldump -p thepassword -u theussr --all-databases > databases.sql
What happens is that the following error gets into the databases.sql file:
Usage: mysqldump [OPTIONS] database [tables]
OR mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
OR mysqldump [OPTIONS] --all-databases [OPTIONS]
For more options, use mysqldump --help
I am confused as what is going wrong here. I tried with "-r databases.sql" and the file comes out empty with the error being printed in the console.

For me, this works in Jenkins:
mysqldump -hxx.xx.xx.xx -pmy_pwd -umy_user db_name > ${filename}
I am generating the file name with time stamp, like:
filename=$(date +'%Y%d%m-%H_%M').sql

My problem was the space in -p mypassword, however with removing the space it did not work either.
Finally this helped resolve the issue:
export MYSQL_PWD=yourverysecretpassword
mysqldump -u theussr --all-databases > databases.sql

Related

mysqldump syntax error - password being used as database name [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I'm trying to duplicate a MySQL (5.5.64-MariaDB) database on the same server by following this guide: Cloning a MySQL database on the same MySql instance
The accepted answer didn't work so I reviewed the docs over at MySQL and found that the mysqldump Options used --user and --password instead of the -u and -p flags on the linked post.
When I execute this:
mysqldump --user myUser --password myPassword dev_db | mysql -umyUser -pmyPassword staging_db
It firstly asks me to enter a password:
Enter password:
So I enter myPassword although unsure why as it's given in the arguments list.
Then it gives the following error:
mysqldump: Got error: 1049: "Unknown database 'myPassword'" when selecting the database
If I try entering the --username and --password without spaces:
mysqldump --usermyUser --passwordmyPassword dev_db | mysql -umyUser -pmyPassword staging_db
It errors
mysqldump: unknown option '--usermyUser'
The intention of this is to copy dev_db into a database called staging_db. Both of these databases exist on the same server. The username/password I'm using has full access to every database on the MySQL instance.
Why doesn't this work?
If I use:
$ mysql -umyUser -pmyPassword
It connects without any issue and gives me the MariaDB command prompt.
Server is running CentOS Linux release 7.7.1908 (Core)
Database version:
$ mysql -V
mysql Ver 15.1 Distrib 5.5.64-MariaDB, for Linux (x86_64) using readline 5.1
You can't have a space before the password.
--password=myPassword
or
-pmyPassword
When the --password option doesn't have a directly connected parameter, it means to prompt for the password.

Can't insert data to mysql database with awk [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I'm trying to insert some data fom a .tsv file to a mysql database using awk. When I run this, I just get the mysql rules back at the command line. Any ideas?
Here's the command I am using:
awk '{print "INSERT INTO scores(id, score) VALUES('\''"$1"'\'', "$2");"}' "data.tsv" | mysql -u "user" -p "passw" db
I'm not getting any error messages back, but I check my database and no rows have been inserted.
You can try to remove the space between -p "passw", like this:
| mysql -u "user" -p"passw" db
The other answer already hinted that the -p flag has special, counter-intuitive behavior in the mysql client. If you have a space after it, it makes the mysql client prompt you for a password. The argument following is NOT taken as the password, it's taken as the next argument unrelated to -p.
The following two commands are equivalent:
mysql -u <user> -p <databasename>
mysql -p -u <user> <databasename>
If you want to include the password, you must have no space after the -p:
mysql -u <user> -p<password> <databasename>
To make scripts more clear, I like to use the long option names:
mysql --user=<user> --password=<password> <databasename>
But you shouldn't be using passwords on the command-line anyway, because then anyone who can run ps can see your password. Instead, put user & password into an options file and have the client read it.
mysql --defaults-file my.cnf <databasename>
Your awk code is going to output a long series of SQL injection vulnerabilities. I mean, you're trusting that all the content in your .tsv file is safe to insert, won't contain any characters like apostrophes that will do anything unexpected to the SQL syntax. For example, what happens if $1 is "O'Hare"?
Awk doesn't have any function to do string-escapes to protect you from this, nor any feature to do parameterized queries, which is a better method of running safe SQL statements with dynamic values.
I have used awk for other tasks for many years, but I wouldn't use it for this task. For example, in Ruby:
require 'mysql2'
require 'csv'
client = Mysql2::Client.new(:host => "localhost", :database => "test", :username => "...")
sql = client.prepare("INSERT INTO scores (id, score) VALUES (?, ?)")
CSV.open('data.tsv', col_sep: "\t", liberal_parsing: true) do |csv|
csv.each do |row|
sql.execute(*row)
end
end
Another alternative to load TSV files, with much better performance, is to use mysqlimport --local. But there are some configuration values you need to set to get this to work on a default MySQL instance, and the filename must have the same name as the table (except for the .tsv file extension).
Example: I loaded a .tsv file with four lines of text into a table test.scores:
mysqlimport --local test scores.tsv
test.scores: Records: 4 Deleted: 0 Skipped: 0 Warnings: 0

Mysqldump syntax error

I'm currently trying to execute a dump on mysql schema, but it keeps showing a message of sql syntax.
The command that I'm using is:
mysqldump -u root -p password "logicstore" > "c:\backup.sql";
Is that a punctuation issue or something like that?
PS: I've already tried different syntaxes. I've seen on others questions like these.
You can't set password in command line. And it is much more safe to use -r instead of pipe...
mysqldump -u root -p <database_name> -r <file_name>
If you want to use it without asking for password, you have to edit cardinals in .my.cnf file:
[mysqldump]
user=root
password=<password>

Mysql dump code using perl script [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I want to do the mysql-dump using perl script.Backup from some tables from mysql database in perl script.
system(mysqldump -u username -pPassword databasename database table > to /local path) or die..;
Tell me this line which will store backup file of tables to the local path.
Have you tried running that line from the command prompt? It looks like it should work. Are you putting the command in quotes?
system('mysqldump -u username -pPassword databasename database table > to /local path') or die('This failed');

how to insert sql dump into remote mysql server using PuTTY? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
Hi I want to insert sql database dump file in remote mysql server machine. i am using currently putty tool for doing this task. i have used lot of command but i am not able to do this. and i have also created database on that server but now i want insert database sql dump from server directory into mysql server.
I have also uploaded sql dump into home directory RHEL OS remote server machine.
i have used some command like -
mysql> use database_name;
mysql> mysql -u username -p database_name < /home/dump.sql;
mysql> mysql -u username -h host_ip -p database < /home/dump.sql;
mysql> mysql -u username -h host_ip -p database < /home/dump.sql;
mysql> mysql -u username -h host_ip -p dbpass -d database < /home/dump.sql;
mysql> mysql -u username -h host_ip database < /home/dump.sql;
mysql> plink mysql -u username -h host_ip -p database < /home/dump.sql;
and other command but i could not import sql dump into db server.
Please help me.
Thanks.
i think you are missing the password after -p syntax is
mysql -u username -p password db_name < /home/dump.sql
other possibility is that you are not providing proper directory or complete path of dump file