Change Is Inevitable
  • Home
  • MySQL
    • MySQL-Articles
    • AWS RDS
    • Percona Xtradb Cluster
    • MariaDB
    • Galera Cluster
    • ProxySQL
    • MySQL-Scripts
    • MySQL tools
    • MySQL Resources
  • Tools
    • MySQL Advisor
    • MySQL Random Data Generator
    • Postgresql Random Data Generator
    • Clean Prompt
  • General
    • binary-to-decimal
    • Fermat’s Theorem
    • Review
    • Just for fun
    • Personal
  • Contact Me
    • Copyright
    • MySQL Podcast (Youtube)
    • MySQL Podcast (Spotify)
Recent Posts
  • MySQL INSTANT DDL breaks EXCHANGE PARTITION
  • How to setup and use Percona Binlog Server (PBS)
  • MySQL Major Version Upgrade Checklist – how to
  • InnoDB Flushing is simple – explained
  • MySQL Tools for Performance Tuning and Test Data Generation
Recent Comments
  • Kedar on MySQL INSTANT DDL breaks EXCHANGE PARTITION
  • Jean-François Gagné on MySQL INSTANT DDL breaks EXCHANGE PARTITION
  • Reggie on A Unique Foreign Key issue in MySQL 8.4
  • Kedar on How to fix write latency in MySQL 8.4 Upgrade
  • Kedar on How to fix write latency in MySQL 8.4 Upgrade
Home » routine
Change Is Inevitable

Kedar Vaijanapurkar's Blog for MySQL, technology and various subjects

  • Home
  • MySQL
    • MySQL-Articles
    • AWS RDS
    • Percona Xtradb Cluster
    • MariaDB
    • Galera Cluster
    • ProxySQL
    • MySQL-Scripts
    • MySQL tools
    • MySQL Resources
  • Tools
    • MySQL Advisor
    • MySQL Random Data Generator
    • Postgresql Random Data Generator
    • Clean Prompt
  • General
    • binary-to-decimal
    • Fermat’s Theorem
    • Review
    • Just for fun
    • Personal
  • Contact Me
    • Copyright
    • MySQL Podcast (Youtube)
    • MySQL Podcast (Spotify)

Browsing Tag

routine

2 posts

How to fix definer does not exist error 1449 MySQL

  • Kedar
  • March 23, 2015
Explaining and providing solutions of MySQL error 1449: The user specified as a definer does not exist using SQL SECURITY INVOKER and DEFINER.
View Post
mysql-random-data-generator
  • MySQL
  • MySQL-Scripts
  • 19 comments

How To Generate Random test Data In MySQL

  • Kedar
  • July 5, 2012
Are you tired of manually generating test data for your MySQL tables? If you’re looking for random data generator, look no further! Introducing the MySQL Random Data Generator, a powerful…
View Post
MySQL Podcast (Youtube)
RSS feed: MySQL Podcast (Spotify) MySQL Podcast (Spotify)
  • MySQL Major Version Upgrade Checklist (Zero Downtime Strategy)
    Upgrading MySQL major versions in production is never just a version bump - it’s a carefully planned process involving compatibility checks, replication strategy, testing, and controlled cut-over.In this episode, we walk through a practical MySQL Major Version Upgrade Checklist based on real-world DBA workflows. We are covering MySQL replication as base setup for upgrade. It […]
Search:
... ...
  • MySQL INSTANT DDL breaks EXCHANGE PARTITION
  • How to setup and use Percona Binlog Server (PBS)
  • MySQL Major Version Upgrade Checklist – how to
  • InnoDB Flushing is simple – explained
  • MySQL Tools for Performance Tuning and Test Data Generation

19 responses to “How To Generate Random test Data In MySQL”

  1. Dirk Avatar
    Dirk
    June 12, 2020

    I like this approach very much. Unfortunately in my case it doesn’t work with MySql 8.x. When I run the procedure, it keeps saying that there is an error in the SQL syntax near ‘NULL’ – any idea ?

    Reply
    1. Kedar Avatar
      Kedar
      April 14, 2023

      better late than never!! Would you be able to share your table definition please?

      Reply
  2. Peter Brawley Avatar
    Peter Brawley
    August 6, 2019

    Very useful, very nice.

    Proc populate() needs …

    WHEN col_datatype in (‘date’) THEN
    SET func_query=concat(func_query,’get_date(), ‘);

    … before WHEN … (‘datetime’… )

    Reply
  3. Abi Bellamkonda Avatar
    Abi Bellamkonda
    May 3, 2016

    Great work. Thanks for reusable code. Awesome, simple and effective

    Reply
  4. harshvardhan Avatar
    harshvardhan
    March 5, 2016

    hey,
    I am getting this error:
    ERROR 1172 (42000): Result consisted of more than one row
    any suggestions ?

    Reply
    1. Kedar Avatar
      Kedar
      March 30, 2016

      Well that sounds like a bug, though I use this tool fine! Can you provide with more info (like say schema/command)?

      Thanks,
      Kedar.

      Reply
  5. Sid Avatar
    Sid
    September 17, 2015

    Hi Kedar, thanks for this wonderful utility. I have a query for you. Often the tables are linked using PK-FK. How do i take care of this relationship in the test data generated. i.e The entries in FK column should be based on PK values. thanks a ton.

    Reply
    1. Kedar Avatar
      Kedar
      November 9, 2016

      Somehow missed this!! Well presently we do not have this implemented here. What our function does is actually disable fk check and loads the dummy data.
      To make actual relation more work is required here. I will keep it in my todo list but not sure when I’d be able to justify that!
      If you can, do share.

      We do have git if you want to fork: https://github.com/kedarvj/mysql-random-data-generator

      Regards,
      Kedar

      Reply
  6. ashish13g Avatar
    ashish13g
    June 27, 2014

    Sorted it out using ..
    “SET collation_connection = ‘utf8_general_ci’;”

    Reply
    1. Kedar Avatar
      Kedar
      July 1, 2014

      Glad you sorted it Ashish… Hope this has worked for you.
      Cheers.

      Reply
    2. Kedar Avatar
      Kedar
      June 28, 2018

      I have added this to git as an issue here –> https://github.com/kedarvj/mysql-random-data-generator/issues/4

      Reply
  7. ashish13g Avatar
    ashish13g
    June 27, 2014

    hi, I keep getting this error on calling populate
    “ERROR 1267 (HY000) : Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operation ‘='”

    Reply
  8. tsqrd75 Avatar
    tsqrd75
    September 15, 2012

    I like your approach. It’s quick and simple, however when I generate data it inserts nulls and 0 into the database. Any idea?

    I have one suggestion for the size of the table names. 20 is too short. It needs to be longer to support longer table names.

    Reply
    1. tsqrd75 Avatar
      tsqrd75
      September 16, 2012

      I figured out my problem. I wasn’t passing in the correct db name. Thanks much for the script! It’s exactly what I needed. Not many scripts out there that can:

      1. generate data based on the schema
      2. generate random data
      3. can generate data without any configuration

      This is nice. I hope you continue to build on it!

      Reply
      1. Kedar Avatar
        Kedar
        September 17, 2012

        Good to hear you fixed ur problem. Do share as you like this.

        keep visiting,
        Kedar.

        Reply
  9. itoctopus Avatar
    itoctopus
    September 9, 2012

    The routine to create test data can and should be created from PHP (or your programming language). The logic should never be in the database, even for the testing logic.

    The above code can be confusing and I’m not sure if it works across the board – what if you have images stored in the database? Will the code above work?

    Reply
    1. Kedar Avatar
      Kedar
      September 11, 2012

      Hello itoctopus,

      As already said, these are mysql stored procedure & functions combinely generates dummy data that aimed to be used only for testing purpose. I found it useful and hence shared.

      Logically this script fetches table’s mata data and as per each field’s datatype, it generates random data for respective datatype. If any of the datatype is not handled it generates a varchar data.

      I’ve tested it and use it for testing purposes. I do keep updating it as per requirements.

      About your question, ofcourse BLOB datatype hasn’t been considered here but it will generate dummy VARCHAR data for that! You can ofcourse write a function and update procedure to generate BLOB data.

      I hope I cleared your concern. Do try and let me know.

      Thanks,
      Kedar.

      Reply
    2. Ralph Smith Avatar
      Ralph Smith
      February 20, 2015

      Alright, most of us know that. This is an SQL, not a PHP solution.

      Maybe. You haven’t tried it yet have only negative things to say.

      I personally like seeing his method and also look and find how I might change things.

      Reply
  10. Satish Patel Avatar
    Satish Patel
    July 6, 2012

    Its nice..

    Reduced my work to insert records for testing purpose. Just need to access the function…

    Reply
Change Is Inevitable
Designed & Developed by Code Supply Co.