<p>I've connected to a MySQL database using Perl DBI.  I would like to find out which database I'm connected to.</p>

<p>I don't think I can use:</p>

<pre><code>$dbh-&gt;{Name}
</code></pre>

<p>because I call <a href="http://dev.mysql.com/doc/refman/5.0/en/use.html" rel="noreferrer"><code>USE new_database</code></a> and <code>$dbh-&gt;{Name}</code> only reports the database that I initially connected to.</p>

<p>Is there any trick or do I need to keep track of the database name?</p>

You can ask mysql:
```
```
($dbname) = (each %{$dbh->selectrow_hashref("show tables")}) =~ /^Tables_in_(.*)/;
```
```
Update: obviously select DATABASE() is a better way to do it :)