How to generate unique id in MySQL?

前端 未结 16 2639
生来不讨喜
生来不讨喜 2020-11-29 03:17

I\'m programming a script using PHP and MySQL and I want to get a unique id (consisting of a string: capitals and small letters with numbers) like: gHYtUUi5b.

16条回答
  •  臣服心动
    2020-11-29 04:11

    If you use MySQL with version higher than 5.7.4, you can use the newly added RANDOM_BYTES function:

     SELECT TO_BASE64(RANDOM_BYTES(16));
    

    This will result in a random string such as GgwEvafNLWQ3+ockEST00A==.

提交回复
热议问题