To Connect Deno with MySQL Server, follow these steps:
Step 1: Install and Configure MySQL
You need to have MySQL installed in your system. If you are using Mac, you can follow this article to install MySQL.
Once MySQL is installed, login to MySQL shell using the following command.
At the time of writing this tutorial, Deno drive for MySQL does not support password-based authentication, so to test it out, leave the password blank
Create a new database.
Select the database.
Create a new table.
Add data in the table.
Step 2: Connect to MySQL using Deno
Assuming you have deno installed in your machine. if not, check out the official installation guide.
If you are interested to learn about the Deno concepts and how Deno works, check out this tutorial.
Here is our program to connect to MySQL using Deno.
const client = await new Client().connect({
hostname: "127.0.0.1",
username: "root",
db: "codeforgeek_test",
poolSize: 3, // connection limit
password: "",
});
const users = await client.query(`select * from users`);
console.log(users);
await client.close();
Run the program using the following command.
This should print the data from the table.
Deno is currently in the development mode and so are third-party deno modules. I do not recommend it for production at all.