Good evening
I am trying to insert data from one table to another in my script and it comes up with database not found - have I done something wrong?
mysql -e INSERT INTO mysql.db SELECT * from "$cpuser"_mysql.db;
CPUser is a variable manually assigned earlier in the script.
From the CLI I can select * from both
Output from comment;
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 ''domain7mysql4'_mysql.db' at line 1
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 ''domain7mysql4'_mysql.user' at line 1
-se expects a string, so you need to provide one
mysql -e "INSERT INTO mysql.db SELECT * from `${cpuser}_mysql`.db;"
or
mysql -e "INSERT INTO mysql.db SELECT * from ${cpuser}_mysql.db;"
if there are no reserved text
Related
Attempting to perform operations with a random integer in SQL.
The following code works perfectly as intended when run as pure SQL, but triggers a syntax error when attempting to save it into a stored procedure.
SET #sample_count = (SELECT count(*)
FROM cinder_sample);
SELECT #sample_count;
SET #random_ID = (SELECT FLOOR(RAND()*#sample_count));
SELECT #random_ID;
Any ideas as to what could be going wrong?
The exact error triggered is:
"The following query has failed: "CREATE DEFINER=root#localhost PROCEDURE play_random_sp() NOT DETERMINISTIC CONTAINS SQL SQL SECURITY DEFINER DELIMITER // SET #sample_count = (SELECT count() FROM cinder_sample)// SELECT #sample_count// SET #random_ID = (SELECT FLOOR(RAND()#sample_count))// SELECT #random_ID"
MySQL said: #1064 - 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 '// SET #sample_count = (SELECT count(*) FROM cinder_sample)// SELECT' at line 1"
I want to add a new function to an existing MariaDB Database. This is the update script:
DELIMITER //
CREATE FUNCTION second_diff(dateColA timestamp, dateColB timestamp) RETURNS INT
BEGIN
DECLARE diff INT;
if dateColB is null then
SET diff = TIMESTAMPDIFF(SECOND, dateColA, current_timestamp);
else
SET diff = TIMESTAMPDIFF(SECOND, dateColA, dateColB);
end if;
RETURN diff;
END;
//
DELIMITER ;
UPDATE version SET current_version = '1.0.1';
When I am running it, it fails with the following errors:
Error executing: DELIMITER //
CREATE FUNCTION second_diff(dateColA timestamp, dateColB timestamp) RETURNS INT
BEGIN
DECLARE diff INT
. Cause: java.sql.SQLSyntaxErrorException: (conn=1720684) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'DELIMITER //
else
SET diff = TIMESTAMPDIFF(SECOND, dateColA, dateColB)
Error executing: if dateColB is null then
SET diff = TIMESTAMPDIFF(SECOND, dateColA, current_timestamp)
. Cause: java.sql.SQLException: (conn=1720684) Unknown system variable 'diff'
Error executing: else
SET diff = TIMESTAMPDIFF(SECOND, dateColA, dateColB)
. Cause: java.sql.SQLSyntaxErrorException: (conn=1720684) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'else
end if
Error executing: end if
. Cause: java.sql.SQLSyntaxErrorException: (conn=1720684) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'end if' at line 1
RETURN diff
Error executing: RETURN diff
. Cause: java.sql.SQLSyntaxErrorException: (conn=1720684) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'RETURN diff' at line 1
END
Error executing: END
. Cause: java.sql.SQLSyntaxErrorException: (conn=1720684) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'END' at line 1
//
DELIMITER
Error executing: DELIMITER
. Cause: java.sql.SQLSyntaxErrorException: (conn=1720684) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'DELIMITER' at line 1
UPDATE version SET current_version = '1.0.1'
EDIT: This only fails when I am running this migration script at a different server. On my local machine everything is working fine. I was already checking the version numbers of both different MariaDBs. They are both the same.
I found the issue. When running the migration script at the different server, mybatis was used to execute it. According to this issue, you need a special syntax when using Delimiter. So instead of using
DELIMITER // and DELIMITER ;
it was necessary to write
-- #DELIMITER //and -- #DELIMITER ;
i am pentester and i am testing error-based sql injection in limit clause on my MariaDB 5.5.65 server. There is some trouble.
MariaDB> select * from tables where 1=1 limit 1,1 procedure analyse(EXTRACTVALUE(1370,CONCAT(0x5c,0x716a6a6b71,select '123',0x7178627171)),1);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'select '123',0x7178627171)),1)' at line 1
MariaDB> select * from tables where 1=1 limit 1,1 procedure analyse(EXTRACTVALUE(1370,CONCAT(0x5c,0x716a6a6b71,'123',0x7178627171)),1);
ERROR 1105 (HY000): XPATH syntax error: '\qjjkq123qxbqq'
MariaDB> select * from tables where 1=1 limit 1,1 procedure analyse(EXTRACTVALUE(1370,CONCAT(0x5c,0x716a6a6b71,database(),0x7178627171)),1);
ERROR 1105 (HY000): XPATH syntax error: '\qjjkqinformation_schemaqxbqq'
I can retrieve information like database() and version(), but can't use select. Is this feature of MariaDB? Can i bypass this or it's impossible to use select in procedure analyse in MariaDB server?
If you want to use select to return a scalar value in an expression, you have to put it in parentheses to make it a scalar subquery:
EXTRACTVALUE(1370,CONCAT(0x5c,0x716a6a6b71,select '123',0x7178627171))
Should be:
EXTRACTVALUE(1370,CONCAT(0x5c,0x716a6a6b71,(select '123'),0x7178627171))
In this example, that still results in an XPATH error, but that's independent of the question you asked.
I am trying to set the trigger in maria db
The query which I am running is
CREATE TRIGGER TEMP
AFTER INSERT
ON sample_details FOR EACH ROW
BEGIN
UPDATE SAMPLE_MONITOR SET TableDataCount= TableDataCount+ 1,Time=NOW() WHERE
TableName='sample_details';
END; //
delimiter ;
I have a table named 'sample_details' there If any insert is done to that table, I want to increment the count in the row present in SAMPLE_MONITOR table by 1 and also insert the current time
But I am getting the following error after running query
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
So anyone know how to solve this?
Unsure what syntax the error is referring to at this statement :-
Use MyDatabase
CREATE TABLE TestTable
AS (SELECT * FROM dbo.MyTable);
Any help is appreciated!
The dbo suggests that you are using SQL Server. The syntax error is that this syntax is not supported.
The equivalent syntax in SQL Server is:
SELECT *
INTO TestTable
FROM dbo.MyTable;
You need to use like below. The one you are using is Oracle syntax.
Use MyDatabase
Go
SELECT * INTO TestTable FROM dbo.MyTable
GO