xXxrk04
xXxrk04

Reputation: 195

SQL results in Batch FIle

Sir. this is my code

@echo off 
SET path=C:\Users\neca\Desktop cd C:\wamp\bin\mysql\mysql5.5.24\bin 

FOR /F "tokens=*" %%D IN ('mysql -uroot -e "SHOW TABLES from sample"') do echo %%D

pause

BUT in my db I only have 2 tables (sample and test). Why is it that the output of this code is

Tables_in_sample 
sample 
test

where Tables_in_sample is a table that i did not made.

Upvotes: 0

Views: 370

Answers (2)

xXxrk04
xXxrk04

Reputation: 195

@echo off SET path=C:\Users\neca\Desktop cd C:\wamp\bin\mysql\mysql5.5.24\bin

FOR /F "tokens=*" %%D IN ('mysql -uroot -N -B -e "SHOW TABLES from sample"') do echo %%D

Upvotes: 0

RolandoMySQLDBA
RolandoMySQLDBA

Reputation: 44343

The Tables_in_sample is just the header from the mysql client

EXAMPLE

mysql> show tables from mysql;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| event                     |
| func                      |
| general_log               |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| innodb_index_stats        |
| innodb_table_stats        |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| proxies_priv              |
| servers                   |
| slave_master_info         |
| slave_relay_log_info      |
| slave_worker_info         |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
28 rows in set (0.00 sec)

mysql>

See the header of the output is Tables_in_mysql

SUGGESTION

Just disable headers using -ANe instead of just -e

@echo off 
SET path=C:\Users\neca\Desktop cd C:\wamp\bin\mysql\mysql5.5.24\bin 

FOR /F "tokens=*" %%D IN ('mysql -uroot -ANe "SHOW TABLES from sample"') do echo %%D

pause

Give it a Try !!!

Upvotes: 3

Related Questions