简体   繁体   中英

Creating temporary tables with random names in MySQL

I wanna create temporary tables with random names in a MySQL stored procedure. I also need to store the name in order to access the table from another stored procedure. I was thinking of using MD5 hashes:

SELECT md5(RAND()+CURRENT_TIMESTAMP());

I wonder if this will generate totally collision free strings or not?

You could use uuid() and remove the dashes from the result... that is the closest thing I can think of that would give you anything reliably unique.

select concat("table_prefix_", replace(uuid(), '-', '')) as unique_name; 

it would end up being like this:

mysql> select concat("table_prefix_",replace(uuid(), '-', '')) as unique_name;
+-----------------------------------------------+
| unique_name                                   |
+-----------------------------------------------+
| table_prefix_39f14dd9418011e3bd86c0cb38cd4f18 |
+-----------------------------------------------+
1 row in set (0.00 sec)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM