1

THE ISSUE

This is a simple question that has a verifiable answer somewhere, I just can't seem to find it. This is a "how stuff works" type question, as opposed to a "help me fix a bug". I'm trying to understand how mysqldump works.

WHAT I'VE TRIED ALREADY

I Googled how does mysqldump know what databases exist and where they are located? to no avail. I also posted the same query on Stack Overflow, but did not find a clear answer.

The most useful link was repeated references to the manual here. Unfortunately, that article doesn't have a clear answer to how mysqldump works.

MY QUESTIONS

The following questions are actually multiple aspects of the same main question to gather the most complete understanding from various perspectives.

  1. Why can't I run it from the MySQL console CLI, instead of the Windows command line?

  2. If I add the path to mysqldump.exe to my Windows system path will I be able to run mysqldump from any path in my Windows command line, or are the other obstacles to consider?

  3. I have multiple instances of mysqldump.exe installed on my system. Two in WAMP and 2 in a standalone Apache 2.4 install. How can I know which version of mysqldump is being called when I type 'mysqldump' at the command prompt -- especially if the Windows PATH environment variable has the path to two different installs of mysqldump.exe? Is there a msyqldump which or something similar?

  4. When I run mysqldump at the Windows command prompt, since it is not run within the MySQL console, how does the program know what the list of available databases are?

halfer
  • 19,824
  • 17
  • 99
  • 186
  • 1
    mysqldump program most likely queries the `information_schema` database for information existing databases and tables.. If you want to know how the program works just download the source code. – Raymond Nijland Jun 21 '18 at 11:34
  • @RaymondNijland Interesting. I will see if I can find the source code in github and try to track it down. Thanks – Eric Hepperle - CodeSlayer2010 Jun 21 '18 at 13:36
  • @RaymondNijland Well I've been looking into it and can't seem to figure out what is going on. `I'm not an expert hacker` ... I've recently realized that reverse engineering complex software and understanding source codes with too many dependencies does not come easily to me. I found this: https://github.com/twitter/mysql/blob/master/client/mysqldump.c, and this: https://github.com/mysql/mysql-server/tree/8.0/client/dump ... it's possible I'm on the right track, but I really can't tell and it just is so thick and complex -- and it's in C, which I'm not great at. Any ideas? – Eric Hepperle - CodeSlayer2010 Jun 21 '18 at 14:00
  • Check out the functions dump_all_tablespaces() and dump_all_databases() believe that that will answer your question within github.com/twitter/mysql/blob/master/client/mysqldump.c .. dump_all_databases() simply is using `SHOW DATABASES` as query. dump_all_tablespaces() is using information_schema database to get the information about tablespace file locations locations.. That would cover your `how does mysqldump know what databases exist and where they are located?` question i believe. – Raymond Nijland Jun 21 '18 at 17:57
  • Also the mysqldump doesn't use a file location to dump a table.. it just executes a SELECT query and converts the data into a INSERT query matching the table structure.. – Raymond Nijland Jun 21 '18 at 18:08
  • @RaymondNijland I appreciate those hints. I already considered those files but the trouble is -- as I indicated in bullet-point 3 -- _I have multiple versions/installations of MySQL on my computer. So, if both version of MySQL are pointed to in my PATH environment variable, how do I know which mysqldump is executing, and once I know that, is there some master table or .ini file that records where the database schema for that particular installation is stored, or does it use some kind of global database schema? The issue here is multiple installations running side-by-side. Thanks for your help – Eric Hepperle - CodeSlayer2010 Jun 21 '18 at 18:15

0 Answers0