Not understaning how jenkins ci build works - mysql

i have my project in jenkins, when you build it, it finds the script/cibuild script and executes whatever you have in there. I run the script from my project directory and all is fine, i run the build from jenkins, i get errors? i dont understand?
my script/cibuild script:
#!/bin/sh
# This script file is the entry point to ci.miranetworks.net build/test process.
# It is executed by jenkins, from the root directory
#
echo "1. cd into script "
cd script
echo "2. run createmysqldb test_traffic test_user password"
./createmysqldb test_traffic test_user password
echo "3. cd back into root dir "
cd ..
echo "4. create table with sql with: "
mysql -u test_user --password=password test_traffic < ./phoenix/data/sql/lib.model.schema.sql
export WORKSPACE=phoenix
export SYMFONY=$WORKSPACE/lib/vendor/symfony/lib
(cd $WORKSPACE
echo "6. Clearing the cache"
./symfony cc
echo "7. Run unit test"
./symfony php test/unit/RbcTest.php
)
echo "8. All done and exiting"
exit 0
so when i log onto mysql command with mysql -u test_user --password=password test_traffic it is succesfull then i do GRANT ALL and i also get:
ERROR 1045 (28000): Access denied for user 'test_user'#'localhost' (using password: YES)
although in createmysqldb i do: Q2="GRANT ALL ON . TO '$2'#'localhost' IDENTIFIED BY '$3';"
can anyone explain why i get an access denied?
I have another issue with the same script but want to sort out this one first :)
thanks

As far as in MySQL i know you need to change
ALL ON . TO ...
into
ALL ON .* TO ...
to grant access to all tables ?

Related

script for MySQL with user and password entered as a parameter

As another post (Script for MySQL backup to multiple files), I received help to create a Powershell script that creates backup of MySQL databases and generates multiple files, one for each database. As can be seen, the script makes a pipeline between a command mysql and mysqldump.
My intention now is to eliminate the user information and password directly in the script. As another link (How to perform a mysqldump without a password prompt?), I created the my.cnf configuration file MYSQL_HOME, passing the information on [mysqldump], and used the flag --defaults-extra-file. The problem is that this flag does not work for mysql.exe, so could not use this solution.
To avoid leaving the user and password information directly in the script, I used another post (How to handle command-line arguments in PowerShell), which shows how to configure parameters input into Powershell scripts. With that, my script looked like this:
param (
[string]$username = $(throw "-username is required."),
[string]$password = $(Read-Host "Input password, please" )
)
$BACKUPDATE = Get-Date -UFormat "%Y-%m-%d_%H%M%S"
$BKPFOLDER='E:\bkp'
$MYSQL_HOME="C:\MYSQL"
Set-Location "$MYSQL_HOME\bin"
& .\mysql.exe -N -s -r -u $username -p$password -e 'show databases' | % {
& .\mysqldump.exe -u $username -p$password --single-transaction $_ |
Out-File "$BKPFOLDER\${_}_$BACKUPDATE.sql" -Encoding Ascii
}
When I run the following command:
test.ps1 -username bkpuser -password mypass
I get the following message:
ERROR 1045 (28000): Access denied for user 'bkpuser'#'localhost' (using password: YES)
But there is no access permission problem, because if I replace the values โ€‹โ€‹of $usename and $password to call the mysql and mysqldump by correct values โ€‹โ€‹(excluding the parameter), the command works.
What should I change?
PowerShell's parser can't determine where commandline argument ends and vairable name starts. You can see this clearly in ISE, because $password should be red, but it's blue:
Just add space between -p and $password or use "=": --user=$username --password=$password

Linux Script & MySql operations not working, When Invoked from other script

I have written this piece of code to insert rows into table if not there, else, update the 'cnt' by one more. This works very well, when I invoke it from command line, when I invoke it from shell script, this does not work.
file=$1
echo "$0: Path to store $file" ;
res=`mysql -e "use spam_sending_scripts; select * from spamemailcount where path = '$file' limit 0,1"`
echo $res
if [ -z "$res" ]
then
mysql -e "use spam_sending_scripts; INSERT INTO spamemailcount (cnt,path) VALUES(1,'$file');"
echo "Inserting into DB $file , res $res" ;
exit ;
fi
mysql -e "use spam_sending_scripts; update spamemailcount SET cnt=cnt+1 where path = \"$file\"" ;
echo "Updating into DB $file" ;
#mysql -e "use spam_sending_scripts; select * from spamemailcount" >> /var/log/sendmail.log
mysql -e "use spam_sending_scripts; select * from spamemailcount"
root#server [/home]# insertintodb.sh AAA ==> This is working fine.
When I invoke from the other script, this file is executed, But Insert does not work.
I invoke it like: /home/insertintodb.sh $path
The $path variable is getting passed to insertintodb.sh correctly.
I am getting the following Error:
++ mysql -e 'use spam_sending_scripts; select * from spamemailcount where path = '\''hackerssquadron.com/wp-comments-post.php'\'' limit 0,1'
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
Use chmod command to make it executable
chmod ugo+x insertinodb.sh
Then try calling it same as #Jdamian suggested
bash -x /home/insertintodb.sh "$path"
This problem is solved.
When I try to invoke the script from the command line, It is working fine.
Reason => I am running this script as a root. So no problem
When I invoke the script using another shell script, It is not working.
Reason: This main script is being invoked by apache and It is trying to access the root DB, so permission denied.
Based on input from Skynet & Jdamian, I am able to debug it and resolve it.
Thank you very much for support, As usual this is one of the best place to get the technical queries resolved quickly by experts.

bash check mysql connect

I'm writing a bash script to do some operations against a database on my debian squeeze Server.
I have noticed that if I enter a wrong password for root, the prompt will be closed and I won't be asked to try again... that's not very convenient!
So I was trying to create a loop that attempts to connect to MYSQL and save the password for later if successful.
I tried this, but it doesn't work.
Instead, I receive this error:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
read -s -p "Enter MYSQL root password: " mysqlRootPassword
while [[ -n `mysql -u root -p$mysqlRootPassword` ]]; do
read -p "Can't connect, please retry: " mysqlRootPassword
done
I am not very experienced in bash scripting, any help would be awesome!
I don't think you need the [[ -n backtic ... ]]; test nested like that. Try:
read -s -p "Enter MYSQL root password: " mysqlRootPassword
while ! mysql -u root -p$mysqlRootPassword -e ";" ; do
read -s -p "Can't connect, please retry: " mysqlRootPassword
done
while evaluates any command group upto a closing ; do and checks the return code of last command executed to determine if the loop should be executed. Because you are looking for a failure, you have to precede the test with a logical NOT (!) OR you can use the syntactic equivalent, i.e.
until mysql -u root -p$mysqlRootPassword -e ";" ; do
read -s -p "Can't connect, please retry: " mysqlRootPassword
done
which you can think of as 'until mysql works correctly, keep trying to get the right password'.
Unfortunately, I don't have access to a mysql installation, so this is untested.
I hope this helps.

Bash user input Mysql login

Will start with what I am trying to accomplish. I wrote up a menu script to add a new database and echo back to screen the results. But can't seem to get it to login with a variable.
Heres the part I am having problems with:
#!/bin/bash
while [[ "$yn" != "Yes" && "$yn" != "Y" && "$yn" != "y" && "$yn" != "yes" ]]; do
echo " Please, type password for root user. #"
read -r mysqlrp
echo " You have entered $mysqlrp as your MySQL password #"
echo " Is this correct? (Yes or No) #"
read yn
done
mysql -u root -p$mysqlrp
have also tried:
mysql -u root -p${mysqlrp}
as well as mysql -u root -p'${mysqlrp}'
I get the following:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
even though when I try without the script works fine.
Please help,
Thanks in advance,
Joe
To supply a password directly in the command line string, you should use mysql --password=[password]. See this article.
And to prompt the user for a password, you should probably use something like this.
#!/bin/bash
read -p "Username: " uname
stty -echo
read -p "Password: " passw; echo
stty echo
You must not ever print the password. And it should not be seen while typing it in either.
#!/bin/bash
read -p "Username: " uname
stty -echo
read -p "Password: " passw; echo
stty echo
mysql --user=$uname --password=$passw
That script works for me. If it doesn't for you, please check that your mysql permissions allow you to login from localhost.
In a shellscript, you can do
set -x
to see what the command being executed looks like.
You should prolly do mysql --password="$mysqlrp". '$mysqlrp' -> '$mysqlrp'.
In your real script, I suppose you probably want to do
read -p "Password, plz:" -s mysqlrp
In order to properly answer the question, the actual error you get would be helpful. [UPDATE: answered in comment.]
Also, note that if your query is longrunning, your password will be visible in "ps -ef"

How can I check the mysql connection for a user/password using batch/shell script

How can I check the mysql connection for a user/password using batch/shell script?
I've user name and password, and I need to authenticate whether they are correct or not, but how?
I tried this way:
I've created a batch file "run.bat" with "mysql -u User--password=UserPassword < commands.sql"
"commands.sql" file contains "\q"
When I run the file "run.bat" the output is nothing when User/Password are correct and "ERROR 1045 (28000): Access denied for user ... " when User/Password are incorrect. Now can we capture this output, and decide whether the connection is successful or not, if yes how?
Regards
I found a solution as below:
#echo OFF
echo \q | mysql -u User --password=UserPassword 2>nul
if "%ERRORLEVEL%" == "0" (
echo CONNECTION SUCCESSFUL
) else (
echo CONNECTION FAILED
)
You can check the return status of mysql. It is stored in the ERRORLEVEL enviroment variable:
mysql -u User--password=UserPassword < commands.sql
if "%ERRORLEVEL%" EQU "0" (
echo OK
) else (
echo FAIL
)
If you are lucky, mysql.exe even returns a specific status for "logon failed" that you can react on. Most applications return 0 on success and something != 0 on failure. Use echo %ERRORLEVEL% right after a command to find out the current value.
A more advanced approach would be to capture and evaluate the STDERR stream of the application. This, however, would be material for a different question.
you could use a ".my.cnf" file
I do this, although id strongly recommend against using your mysql root login
[root#daaorc900c ~]# cat ./.my.cnf
[client]
user=monitoruser
password=whatismonitor
[root#daaorc900c ~]#
Looks like you might be one windows so here is the doc for the "options files" in widnows
http://dev.mysql.com/doc/refman/5.1/en/option-files.html