How do I change current mysql database dynamically in a procedure? -
for our system using multiple databases same structure. example when have 1000 customers, there 1000 databases. we've chosen give each customers own database, can delete data @ once without hassle.
now have update database structure several times year. began write stored procedure loops through schemas. got stuck executing dynamic use statement.
my code follows:
declare v_schema varchar(100); set v_schema = 'someschemaname'; set @querystring = concat('use ', v_schema); prepare s @querystring; execute s; deallocate prepare s;
when execute code error says error code: 1295. command not supported in prepared statement protocol yet
. assume cannot change active database in procedure.
i have searched internet, thing found creating string of each alter query , prepare/execute/deallocate it. hope there better solution this. write shell script loops through schemas , executes sql file on them, prefer stored procedure takes care of this.
does know how make work?
thank help!
edit: use latest stable version of mysql 5.6
if there known databases, try write case.
otherwise, not execute use statement using prepared statements; instead, build other statements (select, insert, update, ...) full name - <database name> + '.' + <object name>
, , execute them using prepared statements.
Comments
Post a Comment