This program
Running mysql.exe via Windows Explorer
This is a possible *.reg file - on some systems, the .sql key may already exist.
[HKEY_CLASSES_ROOT\.sql] @="sqlfile" [HKEY_CLASSES_ROOT\sqlfile\shell\mysql\command] @="cmd.exe /k \"\"C:\\wamp\\bin\\mysql\\mysql5.5.24\\bin\\mysql.exe\" --verbose < \"%l\" \"" |
\" and \\
cmd.exe /k ""C:\wamp\bin\mysql\mysql5.5.24\bin\mysql.exe" --verbose < "%l" " |
Comments
-- any comment, can start after sql statements -- must have a space --This will cause a problem |
/* any comment, can use several lines */ |
mysql.exe Commands
Several other "special" commands are supported
? help; Show the available "special" commands
| help set; | help show; Show help for the specified command -
set and show in these examples
| show variables; | show variables like 've%'; Show all the current option settings
| like allows wild cards % (any) and _ (one) delimiter ^; | delimiter ;^ Change the command terminator to ^ and back to ;
| These commands are needed to define triggers and stored procedures source filename; | \. filename; Read commands from the specified file
| show databases;
| List all the available databases (directories).
| use database; | connect database; Select a directory that will be used if one is not applied.
| connect works, but is not in the help. show tables; | show tables in database_name; List all the user tables
| show create table TableName;
| Show the table's structure - table names are not case sensitive
| |
There are no commands to perform the following function.
set echo on;
With Firebird and isql.exe,
I use this to debug script errors when the script is run via a batch file.
With mysql.exe, add -v to the command line. There is no way to
control this feature from within the console.
| |
Debugging Scripts
When running a script, it is likely that an error will be displayed ... but the command that caused the error will not be displayed.
There are 2 ways to display where the error is
select 'Just a comment' ; |
produces
Batch mode with just one v | When typed in interactive mode and batch mode with -vvv | ||
|
|
Registry Mods
Only show errors | cmd.exe /k " "C:\wamp\bin\mysql\mysql5.5.24\bin\mysql.exe" < "%l" "
Show All | Allows you to see which lines caused the errors cmd.exe /k " "C:\wamp\bin\mysql\mysql5.5.24\bin\mysql.exe" --verbose < "%l" "
| output -> debug.txt | Write to file cmd.exe /k " "C:\wamp\bin\mysql\mysql5.5.24\bin\mysql.exe" --verbose < "%l" > debug.txt "
| debug -> notepad | Write to file and then display it
| cmd.exe /k " "C:\wamp\bin\mysql\mysql5.5.24\bin\mysql.exe" --verbose < "%l" > debug.txt && notepad.exe debug.txt " |
For simple problems, I prefer to display the errors in the command window ... but for more complex errors, or large files where I want to search for the errors, then notepad is more convenient. The last command (actually entered on a single line, wrapped for readability) produces a file that contains the console output and then opens that file in notepad. Notice that cmd supports multiple commands separated by
& | Execute the next command as soon as possible |
---|---|
&& | Wait for previous command to finish without errors, then continue |
< "filename" | Input file - may be fully qualified |
> "filename" | Output file - may be fully qualified |
-v -vvv --verbose | Causes completed commands to be displayed so that the errors are
easier to locate
Seeing the source would be better, but is not available |
-u username --user=user_name | sysdba - overrides the default in the config file |
-p password | whatever you want, if it is omitted, then you will be prompted
-- except when executing external scripts |
Reference - 4.5.1 - The MySQL Command-Line Tool
Registry Mods for *.sql files
Using IE, you could just copy the above text to the clipboard and use that to make your own *.reg file. However, that won't work with Firefox (yet another reason I truly dislike that product.) Therefore, I have provided the following reg file you can download - be sure to modify it for your system before using it.
Author: Robert Clemenzi