MySQL


Uncategorized

Updated Aug 8th, 2021

MySQL is used by WordPress but you don’t really interact directly with it. Maybe if you are manually backing up or migrating the database. You can also add some tables to store your own data.

PhpMyAdmin is still a thing.

Derek Banas has an overview video here.

Adding Tables to MySQL WP Database

Good Resource: “Become a WP Dev” Course. Checkout the section notes here.

But what about using MySQL in a non-WP environment, hooking it up to a node app, or a Next.js app?

Using MySQL with Node

Traversy Media coming to the rescue again with this video here!

Use MySQL on the machine (Author using XAMPP). Using Express for routing. Import “mysql” package and code a simple server and install nodemon.

npm install mysqljs/mysql
const express = require('express')
const mysql = require('mysql')
// create connection
const db = mysql.createConnection({
  host: 'localhost',
  user: 'me',
  password: 'secret',
  // database: 'nodemysql'
})
// connect
db.connect((err) => {
  if(err) {
    throw err
  }
  console.log("MySql Connected...")
})
const app = express()
//create DB
app.get('/', (req, res) => {
  let sql = 'CREATE DATABASE nodemysql'
  db.query(sql, (err, result) => {
  if (err) {
  throw err
  }
  console.log(result)
  res.send("Database created...")
  })
})
app.listen('3000', () => {
  consoel.log("Server is running on port 3000")
})

Paused the video at 12 minute mark.

Using MySQL with Next.js

This should be the similar for any “create-react-app” project.

This is a next.js tutorial on how to fetch data data for a statically generated page using data fetched from a MYSQL data base.

Install “serverless-mysql” package?

Another Indian dude’s video here. Uses the “next-connect” package.

Random

In my travels I stumbled upon planetscale.


Top