skip to Main Content

I have a set of databases as below

mysql> show databases;
+------------------------+
| Database               |
+------------------------+
| information_schema     |
| sys                    |
| system                 |
| test                   |

When I try to access ‘test’ database using the master user I’m getting below error

mysql> use information_schema;
Database changed
mysql>
mysql>
mysql> use test;
ERROR 1049 (42000): Unknown database 'test'
mysql>

Why is this error generating ?
MySQL Version 5.7

2

Answers


  1. Chosen as BEST ANSWER

    Issue seems to be that the database was not properly created.

    create database test;

    Resolved the issue.


  2. This does not strike me as a privilege issue. Otherwise, an error message should denote that as ERROR 1044 (42000): Access denied for user xx to database xxx. It’s more likely there is something wrong with the data file. To demonstrate, we can create a test database.

    mysql> create database test_db;
    Query OK, 1 row affected (0.01 sec)
    
    mysql> use test_db;
    Database changed
    
    -- delete the test_db database directory from OS terminal. e.g in linux shell, execute:
    root@test# rm -rf /path_to_mysql_datadir/test_db
    
    -- back to mysql cli
    mysql> use test_db;
    ERROR 1049 (42000): Unknown database 'test_db'
    
    

    Please also note, if you directly copy a database from a remote host to your current server’s mysql data directory, you are able to switch to the database, but you can not use its tables.

    -- supposing we have just copied a database named db from remote server using scp
    
    -- back to mysql cli
    mysql> use db;
    Database changed
    
    mysql> show tables;
    +-------------+
    | Tables_in_db |
    +-------------+
    | p           |
    +-------------+
    1 row in set (0.00 sec)
    
    mysql> select * from p;
    ERROR 1146 (42S02): Table 'db.p' doesn't exist
    
    

    As you can see , in this case , as mysql server did not register the table of the remote copied database, querying the table returned an error.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search