Make CMD sensitive to use with MySQL?
I have a cleanup scrip in a bat file and i wanted to do the below but the problem is i get a mysql error saying unknown database and showing it as tes开发者_如何学Ctdb. I guess i can change my code testdb but i would like to know.
How do i have windows cmd use case sensitivity so i can execute queries properly instead of always in lower case?
mysql.exe -u root -q "drop database TestDB; create database TestDB;"
cmd.exe
won't change the case of your commands as evidenced with:
echo Hello There
I think your main problem is that you're trying to impose case-sensitivity on an environment that doesn't really support it.
You should probably just embrace case-insensitivity and set lower_case_table_names
to 1
on all your systems if one of them is Windows. From your symptoms, it sounds like it's been set to 0
somehow which is not really kosher. From the docs, values of this variable mean:
0/ Table and database names are stored on disk using the lettercase specified in the CREATE TABLE or CREATE DATABASE statement. Name comparisons are case sensitive. You should not set this variable to 0 if you are running MySQL on a system that has case-insensitive file names (such as Windows or Mac OS X). If you force this variable to 0 with --lower-case-table-names=0 on a case-insensitive file system and access MyISAM tablenames using different lettercases, index corruption may result.
1/ Table names are stored in lowercase on disk and name comparisons are not case sensitive. MySQL converts all table names to lowercase on storage and lookup. This behavior also applies to database names and table aliases.
2/ Table and database names are stored on disk using the lettercase specified in the CREATE TABLE or CREATE DATABASE statement, but MySQL converts them to lowercase on lookup. Name comparisons are not case sensitive. This works only on file systems that are not case sensitive! InnoDB table names are stored in lowercase, as for lower_case_table_names=1.
You can get the current and new-session values by executing:
show variables like 'lower_case_table_names';
show global variables like 'lower_case_table_names';
By the way, you seem to use the wrong option:
-q, --quick Don't cache result, print it row by row. This may slow
down the server if the output is suspended. Doesn't use
history file.
And what you need is -e
:
-e, --execute=name Execute command and quit. (Disables --force and history
file)
The command in your example will fail (with error 1049 on Windows).
精彩评论