Bug #3647 Unable to "USE databasename" if database has been dropped and then recreated..
Submitted: 4 May 2004 9:37 Modified: 4 May 2004 22:12
Reporter: cami sardinha Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Installing Severity:S2 (Serious)
Version:4.1.1 OS:Linux (Fedora Core 1)
Assigned to: CPU Architecture:Any

[4 May 2004 9:37] cami sardinha
Description:
If you drop a database and then CREATE the same database name,
you can not create tables in it.. You first have to drop out of
the mysql client and log back into mysql in order for it to work..

How to repeat:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 4.1.1-alpha-standard-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases;
+----------+
| Database |
+----------+
| greylist |
| mysql    |
| test     |
+----------+
3 rows in set (0.00 sec)

mysql> use greylist;
Database changed
mysql> show tables;
Empty set (0.00 sec)

mysql> CREATE TABLE triplet (
    ->   trip_from varchar(60) NOT NULL default '',
    ->   trip_rcpt varchar(60) NOT NULL default '',
    ->   trip_host varchar(15) NOT NULL default '',
    ->   trip_date int(10) NOT NULL default '0',
    ->   PRIMARY KEY (trip_host, trip_from, trip_rcpt),
    ->   KEY (trip_date)
    -> );
Query OK, 0 rows affected (0.00 sec)

mysql> DROP DATABASE greylist;
Query OK, 1 row affected (0.01 sec)

mysql> CREATE DATABASE greylist;
Query OK, 1 row affected (0.00 sec)

mysql> USE greylist;
Database changed
mysql> CREATE TABLE triplet (
    ->   trip_from varchar(60) NOT NULL default '',
    ->   trip_rcpt varchar(60) NOT NULL default '',
    ->   trip_host varchar(15) NOT NULL default '',
    ->   trip_date int(10) NOT NULL default '0',
    ->   PRIMARY KEY (trip_host, trip_from, trip_rcpt),
    ->   KEY (trip_date)
    -> );
ERROR 1046 (3D000): No Database Selected
mysql> show databases;
+----------+
| Database |
+----------+
| greylist |
| mysql    |
| test     |
+----------+
3 rows in set (0.01 sec)

mysql> use greylist;
Database changed
mysql> show tables;
ERROR 1046 (3D000): No Database Selected
mysql> 

Suggested fix:
no idea..
[4 May 2004 14:31] Tobias Asplund
Bug is only triggered when you DROP/CREATE the database you're currently using.

====================
mysql> USE foo;
Database changed
mysql> DROP DATABASE foo;
Query OK, 1 row affected (0.00 sec)

mysql> CREATE DATABASE foo;
Query OK, 1 row affected (0.00 sec)

mysql> USE foo;
Database changed
mysql> CREATE TABLE foo ( bar INT);
ERROR 1046 (3D000): No Database Selected

====================

mysql> USE test;
Database changed
mysql> DROP DATABASE foo;
Query OK, 1 row affected (0.00 sec)

mysql> CREATE DATABASE foo;
Query OK, 1 row affected (0.00 sec)

mysql> USE foo;
Database changed
mysql> CREATE TABLE foo ( bar INT);
Query OK, 0 rows affected (0.11 sec)

====================

Seems like the client still thinks it's in the database that got dropped, and when you later issue a USE it thinks that you're trying to change to your current database and ignores it?
doing a USE test; USE foo; makes the first example work since you actually change to a different than your "current" database.
[4 May 2004 14:36] cami sardinha
If it the client which is having trouble, then its the client
that is coming bundled with the 4.1.1 binary package as i didnt
not have any mysql package installed on there before..

Using the 4.0 stable binary package doesnt have this issue.

Can you confirm that the problem is infact with the 4.1.1 client
binary or confirm that its not..
[4 May 2004 22:12] Michael Widenius
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html

Additional info:

This is same as bug 2205.
This was fixed in the 4.1 source tree in January and will be in 4.1.2