I have a php/mysql app that users can actually test/submit data to, so I want to delete/drop all the tables in my database and run my sql script to recreate and populate all the tables every hour.
So, in my cpanel, I have a cron job [see below]
/home/lwarinz/call_nw_test_script.sh
#!/bin/bash
mysql -hlocalhost -ulwarinz_hawaii -pdbAdmin67 -elwarinz_northwind \
</home/lwarinz/nw_test_Script.sql;
Note: I have have the query to drop and recreate the tables, but I am using this short query for testing:
USE lfwebz_northwind;
UPDATE employees SET FirstName = "Elizabeth" WHERE EmployeeID = 3;
but no matter what I change/adjust, I get the error below:
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to use near
'lwarinz_northwind' at line 1
I have changed so many things and still nothing works.
I know the db, user and password are correct. I wrote a small db connect code to test, so I am sure. Since I am new to this, write cron jobs, I don't know what to check. Could anyone give me any ideas on what I need test, change, move, etc.?
Any help/suggestions would be greatly appreciated.
/home/lwarinz/call_nw_test_script.sh
#!/bin/bash
mysql -hlocalhost -ulwarinz_hawaii -pdbAdmin67 lwarinz_northwind </home/lwarinz/nw_test_Script.sql;
Because you're specifying the database on command line, dont include the USE as part of your script..
#!/bin/bash
mysql -hlocalhost -ulwarinz_hawaii -pdbAdmin67 lwarinz_northwind \
</home/lwarinz/nw_test_Script.sql;
Script:
UPDATE employees SET FirstName = "Elizabeth" WHERE EmployeeID = 3;
Just wanted to leave this note. I kept plugging away at this and finally got to the point that I knew I had the script correct. Contacted my site provider, for the 4th time, and just made the last guy look at the script and explain why exactly it didn't work. Long story short, there was something "off" in my space that needed to be adjusted [still not sure I believethat], so it works now.
Thanks for everyone's input, I do appreciate it.
Related
When I input a code or anything into MySQL and hit "enter" it moves down and "->" appears. It is as if the code is not going through or the code is not being read.
I have attempted to download "add-ons" but I am really not sure what I am doing. This is for school and I am having trouble getting in touch with the professor.
I am new to this and can't figure out what I am doing wrong. Please help!
Please see image of what it looks like to me.
Please add semicolon ; after the mysql code.
Problem 1: Be aware of the prompt. Either of these
MariaDB >
mysql >
means that you are inside the MySQL commandline tool. You can enter only SQL statements. Most SQL queries need to be terminated by a ; or \G (but not both). To exit that tool:
exit
Or, if you get stuck in certain ways
CTRL-C
exit
Each of these implies a shell script:
$
#
mymachine$
/usr/home/rj $
C:\Users\rj:
and many others
Problem 2: mysqldump is a command, not SQL. So it needs to be executed in a shell script.
Problem 3: There is yet another problem. When it suggested typing 'help;', it did not mean for you to include the quotes. Instead, type just help;.
So I have a server set up to serve payment requests. A user enters their credit card details in a form.
Query to inject here:
$sql = "UPDATE users SET credit_card'".$credit_card."', cvv='".$cvv."', expdate='".$exp."' WHERE userid='".$_SESSION['userid']."'";
I am trying to change another users password from this query.
Where the $credit_card is posted from a form. Im trying to inject the $credit_card part by writing my own query and getting rid of the rest by adding ;-- to the end.
The statement I am using for $credit_card is :
', password='test' where userid='10';--
Now, I am positive this was working yesterday but now the following error appears and I cannot wrap my head around it. Any help please?
Query failed: UPDATE users SET credit_card'', password='test' WHERE userid='20';--, cvv='', expdate='' WHERE userid='20'
Not all database functions accept multiple statements so the ; delimiter may be considered unexpected input.
The syntax for single-line comments in MySQL is -- Foo (please note the white space after the double-dash).
If the server code is yours, you can just print the actually error message generated by the server (and not some generic "something went wrong" text). If it isn't, just copy and paste the SQL code from the error message into your favourite MySQL client.
I'm having a really hard time believing this question has never been asked before, it MUST be! I'm working on a batch file that needs to run some sql commands. All tutorials explaining this DO NOT WORK (referring to this link:Pass parameters to sql script that someone will undoubtedly mention)! I've tried other posts on this site verbatim and still nothing is working.
The way I see it, there are two ways I can approach this:
1. Either figure out how to call my basic MYSQL script and specify a parameter or..
2. Find an equivalent "USE ;" command that works in batch
My Batch file so far:
:START
#ECHO off
:Set_User
set usrCode = 0
mysql -u root SET #usrCode = '0'; \. caller.sql
Simply put, I want to pass 'usrCode' to my MYSQL script 'caller.sql' which looks like this:
USE `my_db`;
CALL collect_mismatch(#usrCode);
I know that procedures are a whole other topic to get into, but assume that the procedure is working just fine. I just can't get my parameter from Batch to MYSQL.
Ideally I would like to have the 'USE' & 'CALL' commands in my Batch file, but I can't find anything that let's me select a database in Batch before CALLing my procedure. That's when I tried the above link which boasts a simple command line entry and you're off to the races, but it isn't the case.
Any help would be greatly appreciated.
This will work;
echo SET #usrCode = '0'; > params.sql
type params.sql caller.sql | mysql -u root dbname
I've been trying to get a shell(bash) script to insert a row into a REMOTE database, but I've been having some trouble :(
The script is meant to upload a file to a server, get a URL, HASH, and a file size, connect to a remote mysql database, and insert the data into an existing table. I've gotten it working until the remote MYSQL database bit.
It looks like this:
#!/bin/bash
zxw=randomtext
description=randomtext2
for file in "$#"
do
echo -n *****
ident= *****
data= ****
size=` ****
hash=`****
mysql --host=randomhost --user=randomuser --password=randompass randomdb
insert into table (field1,field2,field3) values('http://www.example.com/$hash','$file','$size');
echo "done"
done
I'm a total noob at programming so yeah :P
Anyway, I added the \ to escape the brackets as I was getting errors. As it is right now, the script is works fine until connects to the mysql database. It just connects to the mysql database and doesn't do the insert command (and I don't even know if the insert command would work in bash).
PS: I've tried both the mysql commands from the command line one by one, and they worked, though I defined the hash/file/size and didn't have the escaping "".
Anyway, what do you guys think? Is what I'm trying to do even possible? If so how?
Any help would be appreciated :)
The insert statement has to be sent to mysql, not another line in the shell script, so you need to make it a "here document".
mysql --host=randomhost --user=randomuser --password=randompass randomdb << EOF
insert into table (field1,field2,field3) values('http://www.site.com/$hash','$file','$size');
EOF
The << EOF means take everything before the next line that contains nothing but EOF (no whitespace at the beginning) as standard input to the program.
This might not be exactly what you are looking for but it is an option.
If you want to bypass the annoyance of actually including your query in the sh script, you can save the query as .sql file (useful sometimes when the query is REALLY big and complicated). This can be done with simple file IO in whatever language you are using.
Then you can simply include in your sh scrip something like:
mysql -u youruser -p yourpass -h remoteHost < query.sql &
This is called batch mode execution. Optionally, you can include the ampersand at the end to ensure that that line of the sh script does not block.
Also if you are concerned about the same data getting entered multiple times and your rdbms getting inconsistent, you should explore MySql transactions (commit, rollback, etc).
Don't use raw SQL from bash; bash has no sane facility for sanitizing the data beforehand. Generate a CSV file and upload that instead.
I have a lot of services which query the database. All of them work fine but one service calling a stored procedure gives me following error:
Could not find server 'dbo' in
sys.servers. Verify that the correct
server name was specified. If
necessary, execute the stored
procedure sp_addlinkedserver to add
the server to sys.servers.
I have not idea why all the other stored procedures work fine and this one not...
By the way, I use SubSonic as data access layer.
Please run select name from sys.servers from the server which you mentioned as default server in configuration file.
Here in name column values should match with your server names used in the report query.
e.g serverXXX.databasename.schema.tablename
serverXXX should be there in the result of select name from sys.servers otherwise it gives error as got.
It sounds like there is an extra "." (or two) in the mapping - i.e. it is trying to find server.database.schema.object. Check your mapping for stray dots / dubious entries.
Also make sure that the server name matches what you think it is. If you rename the host that SQL Server is running on, you need to rename the SQL Server, too.
http://www.techrepublic.com/blog/datacenter/changing-the-name-of-your-sql-server/192
I had another issue with the same exception so I'll post here if someone stumble upon it:
Be careful if you specify the server name in synonyms. I had a different server name on my staging machine and production and it caused the same 'cannot find server'-error.
(Guess you shouldn't use synonyms that much anyway but it's useful in some migration scenarios)
In my case i was facing same issue with following ,
SqlCommand command = new SqlCommand("uspx_GetTemplate", connection);
but after adding square bracket to stored procedure name it get solved.
SqlCommand command = new SqlCommand("[uspx_GetTemplate]", connection);