I want to write a stored procedure that allows people to create new database users.
I've looked up on the Internet and it seems that the only answer I find is too complex (MySQL Stored Procedure to create user)
This is what I have, but it is not working. MySQL complains about 'psw'.
create procedure create_user(IN name varchar(50), IN psw varchar(50))
begin
create user name identified by psw;
end
I'd like to know if it is possible to implement the procedure following the logic of the one I presented, and if so, how it is done
Related
History etc:
Project is time sheeet entry, currently works in excel now moving to DB
using excel 2010 as front end for rapid application development.
Framework is SAVETODB
I am not a DB expert, i have known how to write select stmt for years but first time designing complete DB
Goal: Saving database table changes entered in excel back to mysql
using mysql stored procedures (it works when the stored procedures code is saved in savetodb)
Not sure how much help I will get on here for SAVETODB (can't locate a product specific form), I have never used it before but if it works then it is brilliant for my needs.
So in SAVETODB you can enter your update/insert/delete queries or you can point it to your saved procedures in your db (mysql). When I enter my mysql statements into savetodb i can save to db from excel, but when saving as procedures in mysql and calling from savetodb i cannot save to db from excel.
The reason I say this isn't working is the savetdb "save" button is greyed out when loading second table
Starting out with getting a couple of fields in order to get the statements correct,
WORKS (ie savetodb allows saving changes) all code in savetodb - these are savetodb settings (green in linked image)
Doesn't work, ie using stored procedures these are savetodb settings (pink in linked image)
edit 0215 updated graphic below, savetdb can also accept a base table if referenced as insert/update/delete procedure. this needs the database name prefaced to table, but even with the database name prefaced to the procedure it still doesn't allow saving. maybe i am referencing the procedure wrong ?
data from framework file 'savetodb_deb.query_list'
[https://drive.google.com/file/d/0B20N5606_8JfTk9DZjVTVTFDaEE/view?usp=sharing]
The following three do work and update data/perform as expected when run from Navicat
MYSQL code for insert procedure - These three are what I am trying to get to work with the second set of savetodb settings
CREATE DEFINER = `root`#`localhost` PROCEDURE `NewProc`(IN `id` int,IN `thenumber` char(25),IN `thedate` datetime)
BEGIN
INSERT INTO time1
set Date = thedate, Reference = thenumber;
END;
MYSQL code for update procedure
CREATE DEFINER = `root`#`localhost` PROCEDURE `NewProc`(IN `idin` int,IN `thenumber` char(25),IN `thedate` datetime)
update `test`.`time1`
SET
`Reference` = 'poop', `Date` = '2015-01-15 00:00:00'
WHERE ID = idin;
MYSQL code for delete procedure
CREATE DEFINER = `root`#`localhost` PROCEDURE `NewProc`(IN `idin` int)
BEGIN
DELETE FROM time1
WHERE
ID = `idin`;
END;
Here is the link to the page at SAVETODB that talks about saving changes
http://
www.savetodb.com
/help4/configuring-saving-changes.htm
So this is actually quite simple within savetodb. Skip all the definer stuff and just enter in the query starting with "Select/insert/update" etc.
Savetodb is an excel add in, they actually create their own db/schema to save all the options so the queries we save as users are simply stored within a table.
to reference excel worksheet cells outside of the data table simply have excel name them (named range) then reference them in your query with : notation.
I've created a stored procedure in Mysql and I was wondering if there is a command that I can get and store the name of the database that this stored procedure lives in?
How about DATABASE() ?
(This text is just filler)
Your Question is wrong?..Your actual question is you have created a stored procedure inside the databases...not how to retrieve the procedure inside the database?
Ans: To know the created procedure:
mysql:\> show procedure status; //to know the procedure name..sam4 function show function staus;
mysql:\> show use create procedure emptab.test1 //emptab is database name,test1 is the procedure..
I'd like to create a procedure from PHP using PDO...I can execute the procedure with PDO, I can create the procedure with the console line or with phpmyadmin, but I'm not able to create this very same procedure from PDO...
I absolutely need to be able to create this procedure from my php code (it's a setup part of a bigger program, the first step checks if the procedure exists with
SHOW PROCEDURE STATUS LIKE 'name_of_procedure'
if the procedure doesn't exists, I try (but fail) to create it (with prepare/execute couple of methods).
I've Googled but come up with nothing that I can get my head around.
Are the performance gains from using stored procedures significant?
Would I still want to use prepared statements in conjunction with stored procs or is it generally a one or the other thing?
Can I create stored procs through PHPMyAdmin and manage them from there as well?
What would a stored procedure look like for something simple like this-
SELECT * FROM table a
INNER JOIN otherTable b
ON a.join_id=b.join_id
WHERE someVar = :boundParam
and how would the PHP work (PDO) to call it and bind its parameter?
Consider this a gentle introduction to stored procedures in MySQL: http://www.mysqltutorial.org/mysql-stored-procedure-tutorial.aspx
You sure can create/manage stored procedures in phpMyAdmin.
I have created one procedure but the time of call this procedure what parameter I can pass to get the output
CREATE DEFINER=`root`#`localhost` PROCEDURE `A`(
In user_id bigint,
Out address varchar(250)
)
BEGIN
select Address into address
from UserDetail_table
where User_ID = user_id;
END
I am creating database at runtime and I want to create the tables in that database at the same time. Can anyone give me any thought on how to do that?
For Example -
I have created one database named 'mydb'
and now in the same process I am trying to create the table I am using the mysql stored procedure for the same.
My proc input will be my dbname. So, my proc looks like
create procedure test(IN dbname varchar(100))
begin
create table `dbname`.`testing`(testid int, testname varchar(45));
end
You can use the PREPARE feature to execute dynamic SQL.