how to use mysql variables when creating database - mysql

set #username = "botany";
set #password = "botany";
set #databaseName = "botanyDatabase";
drop database if exists #databaseName;
this is the code. But it gives the error message:
ERROR 1064 (42000) at line 4 in file: '/home/list/botany/app/botany.sql': 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 '#databaseName' at line 1
So how can i use the variables when creating database.

Related

ERROR 1064 (42000) Delete statement in RDS

I tried to use RDS MySQL to store my data. This statement works in my local DB.
DELETE FROM movie_recommend mr WHERE mr.user_id = 71
But it's not executed in RDS MySQL.
ERROR 1064 (42000): 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 'mr where mr.user_id = 71' at line 1
Any helps what's wrong with the syntax?

MySQL 8: Alter definer of stored procedure

In versions of MySQL prior to 8, altering the definer of a stored procedure is possible by manipulating the mysql.proc table. This table was removed in 8 and replaced by the data dictionary. It looks like the definer can be modified using ALTER PROCEDURE, but for the life of me I cannot get the syntax specified to work.
mysql> alter procedure refresh_basic sql security definer=`foo`#`127.0.0.1`;
ERROR 1064 (42000): 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 '=`foo`#`127.0.0.1`' at line 1
mysql> alter procedure refresh_basic sql security definer='foo#127.0.0.1';
ERROR 1064 (42000): 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 '='foo#127.0.0.1'' at line 1
I also tried both of the above without using =, but got similar errors. How does one actually do this? Thanks!

Getting Database putting into sql file

I am trying to get my database example_dog_names into a sql file. The command I have tried to do this is:
example_dog_names > C:/Users/man/Desktop/dbfile.sql;
The error that I am getting says:
ERROR 1064 (42000): 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
'example_dog_names < C:/Users/man/Desktop/dbfile.sql' at line 1
What am I missing? I am connected to MySQL, and I executed the command:
USE example_dog_names;
Any help is appreciated!

MySQL update Trigger to update data table value After Insert on another table

I have been stumbling on writing some an MySQL trigger and was hopping someone could help me find the most elegant solution to solve my issue. I have Looked many places and cannot seem to find where the bug is in this code. I also tried not adjusting the delimiter as it seems to create problems I am able to create a trigger without setting the delimiter if I replace the update statement by something else.
The code I have is:
USE MyTable
DELIMITER //
--Trigger to update Scheduling 'Status' and 'Retries' values
CREATE TRIGGER `Scheduling-Updatde_After_Result-Insert`
AFTER INSERT ON Results
FOR EACH ROW BEGIN
UPDATE `Scheduling`
SET
Running = FALSE,
Retries = Retries + 1
WHERE ID = NEW.ID;
END//
DELIMITER ;
I get the following errors:
18:03:25 [DELIMITER - 0 row(s), 0.000 secs] [Error Code: 1064, SQL State: 42000] 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 'DELIMITER
CREATE TRIGGER acapella.Scheduling-Updatde_After_Result-Insert
' at line 1
Code: 1064 SQL State: 42000 --- 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 'DELIMITER
CREATE TRIGGER Scheduling-Updatde_After_Result-Insert
' at line 1
18:03:25 [END - 0 row(s), 0.000 secs] [Error Code: 1064, SQL State: 42000] 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 'END
DELIMITER' at line 1
Code: 1064 SQL State: 42000 --- 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 'END
DELIMITER' at line 1

How to display the value of a variable at the commandline in MySQL?

I tried the following -
I created a variable at the command prompt as follows -
mysql> set #myId = 1;
Query OK, 0 rows affected (0.00 sec)
Then, to display it, I tried the following without success -
mysql> show myId;
ERROR 1064 (42000): 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 'myId' at line 1
mysql> show #myId;
ERROR 1064 (42000): 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 '#myId' at line 1
mysql> PRINT #myId;
ERROR 1064 (42000): 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 'PRINT #myId' at line 1
mysql> PRINT myId;
ERROR 1064 (42000): 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 'PRINT myId' at line 1
So how can I display the value of #myId?
Simply SELECT the variable like this:
SELECT #myId;
Here is the MySQL documentation on user-defined variables:
http://dev.mysql.com/doc/refman/5.5/en/user-variables.html
If you're looking for a variable that you set yourself like the OP did, then #MikeBrant's answer is correct:
SELECT #myId;
But if you want to see the MySQL system variables (which is what I came here looking for), then you need to run:
show variables like '%slow%';
or possibly:
show global variables like '%slow%';
SHOW GLOBAL STATUS LIKE '%com_stmt%';
may be used to determine any SHOW GLOBAL STATUS current values using wildcard.
Likewise,
SELECT ##thread_cache_size;
may be used to display any specific SHOW GLOBAL VARIABLES current value.
There are more than 300 GLOBAL STATUS values.
There are more than 400 GLOBAL VARIABLES with or without values. (Could be empty placeholders).
You CAN NOT create a GLOBAL VARIABLE in MySQL.