Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 759 Vote(s) - 3.51 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I find all the tables in MySQL with specific column names in them?

#11
```
select distinct table_name
from information_schema.columns
where column_name in ('ColumnA')
and table_schema='YourDatabase';
and table_name in
(
select distinct table_name
from information_schema.columns
where column_name in ('ColumnB')
and table_schema='YourDatabase';
);
```

That ^^ will get the tables with ColumnA *and* ColumnB instead of ColumnA *or* ColumnB like the accepted answer

Reply

#12
In older MySQL versions or some MySQL NDB Cluster versions that do not have `information_schema`, you can dump the table structure and search the column manually.

mysqldump -h$host -u$user -p$pass --compact --no-data --all-databases > some_file.sql

Now search the column name in `some_file.sql` using your preferred text editor, or use some nifty [AWK][1] scripts.

----------

And a simple [sed][2] script to find the column. Just replace *COLUMN_NAME* with yours:

sed -n '/^USE/{h};/^CREATE/{H;x;s/\nCREATE.*\n/\n/;x};/COLUMN_NAME/{x;p};' <some_file.sql
USE `DATABASE_NAME`;
CREATE TABLE `TABLE_NAME` (
`COLUMN_NAME` varchar(10) NOT NULL,

You can pipe the dump directly in sed, but that's trivial.

[1]:

[To see links please register here]

[2]:

[To see links please register here]




Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through