Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Database exists but returns an error saying "Unknown Database"

I installed WAMP server few hours ago into my Windows 10 64-bit computer. I used phymyadmin to create a database named 'testdb' and tried to connect to it with a php file. I am sure that I created the database, but it returns this error:

"Warning: mysqli_connect(): (HY000/1049): Unknown database 'testdb' in C:\wamp64\www\projects\index.php on line 7"

Here is the php file.

<?php
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_NAME', 'testdb');

$link = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
?>

My problem is kind of similar (but not exactly same) to the following question.:

Database is created but return error as unknown database

(However in that case, the database was not created by the original poster. In this case, I am pretty sure I have created the database.)

Additional information

  1. All wamp services are running.
  2. 'Root' user has privileges to access the database.(proof)
  3. MySQL console confirms the existence of the database. (proof)
  4. Wamp Server version 3.2.2.2
like image 438
Ben MacTavish Avatar asked May 26 '20 18:05

Ben MacTavish


People also ask

How do I fix an unknown database error?

This type of error occurs if you select any database that does not exist in MySQL. Let us first display the error of unknown database in JDBC. To remove this type of error, just go to MySQL command line and show all database names and use the chosen one from there i.e. the database which really exist.

What is error 1049 in MySQL?

Generally, This error indicates that the related database exists in a cPanel user's database map, but the database does not exist in MySQL.

What does “this database does not exist in MySQL” mean?

Generally, This error indicates that the related database exists in a cPanel user’s database map, but the database does not exist in MySQL. The first thing that our Support Engineers perform on seeing this error is to check whether the database exists within MySQL. They does this by running the following command as the root user via SSH:

Why do I get an unknown database error when connecting to MySQL?

When connecting to MySQL, I get an "Unknown Database" error. You connect to the wrong cluster. You connect to a database that doesn’t exist in your specified cluster. Verify that you are using the correct hostname to connect.

What is error of unknown database in JDBC?

This type of error occurs if you select any database that does not exist in MySQL. Let us first display the error of unknown database in JDBC. The Java code is as follows.

What does unknown database status mean in Exchange Server?

Unknown database status in Exchange Server is a sign of an unhealthy or damaged database. Sometimes, you also notice that even though the database is mounted, the Content Index State is ‘ Unknown ’ or ‘ Not Available ’. Although users can access their mailboxes from mailbox databases with ‘ Unknown ’ status, it affects the email delivery.


1 Answers

In the newer versions of Wampserver, the port for MySQL has changed from 3306 to 3308 (you can see it in your first screenshot). You will need to update your connection to specify that port. Otherwise you will be hitting the MariaDB installed with WAMP which does not have that database within it.

define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_NAME', 'testdb');
define('DB_PORT', 3308);

$link = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME, DB_PORT);

As pointed out in the comments, it is also possible to make MySQL your default database which would also solve your problem. You can get the instructions from the DBA Stack Exchange site.

like image 101
John Conde Avatar answered Oct 20 '22 03:10

John Conde