mysql

MySQL syntax examples - create table, primary key, foreign key

Just a quick note here today that if you need some example MySQL database tables, you can use these. I created them for some experiments I ran last night. They show the MySQL create table, primary key, and foreign key syntax:

MySQL show status - show open database connections

MySQL "show status" FAQ: Can you demonstrate how to use the MySQL show status command to show MySQL variables and MySQL status information, such as the number of open MySQL connections?

I don't have a whole lot of time today to give this a detailed discussion, but here is a quick look at some MySQL work that I did recently to show MySQL open database connections.

MySQL - Default a date (timestamp) field to now

MySQL DATE syntax FAQ: How do I set a MySQL DATE field to default to "now", i.e., the current time?

MySQL default date now - Solution

Unfortunately you can't default a MySQL DATE field to "now", but you can get the "now" behavior with a MySQL TIMESTAMP field. The basic MySQL syntax to create a MySQL TIMESTAMP now field is:

last_changed timestamp not null default now(),

where "last_changed" is the name of my field, timestamp is the type of field, it can't be null, and the date/time default is now.

A MySQL 'create table' syntax example

I used to use MySQL every day for years, but over the last two years I haven't used it much. Today I needed to create a MySQL database table, and had to wonder for a few moments what the MySQL CREATE TABLE syntax was. Fortunately I have plenty of examples out here.

Here's a quick example of a MySQL "users" table:

MySQL backup - How to backup a MySQL database

MySQL backup FAQ: How do I back up a MySQL database?

I can't speak about backing up MySQL databases that are modified twenty-four hours a day seven days a week, but on all the MySQL databases I currently work with, there are always times when I can guarantee that there won't be any SQL INSERTs, DELETEs, or UPDATEs occurring, so I find it's really easy to perform a MySQL backup using the mysqldump utility program. Here's how it works.

MySQL restore - How to restore a MySQL database from a backup

MySQL database FAQ: How do I restore a MySQL backup? (Also written as, "How do I restore a MySQL database dump?")

MySQL create database example - How to create a MySQL database and user account for Drupal

MySQL "create database" FAQ: Can you share an example of how to create a MySQL database, including (a) creating the MySQL database and (b) a new MySQL database user, with all appropriate MySQL GRANT permissions for that user?

I've written about the process of How to add/create a MySQL user before, but I just ran across the Drupal installation documentation, which also has a nice description for how to create a MySQL database (for use with Drupal), so I thought I'd include some of their documentation here, along with some notes from my own recent Drupal and MySQL installation.

1) Create a new MySQL database

The first part of the Drupal installation document refers to creating a MySQL database:

A Scala JDBC connection and SQL SELECT example

Scala JDBC FAQ: How can I use the Java JDBC API in my Scala application?

If you want to use a SQL database with your Scala applications, it's good to know you can still use the traditional Java JDBC programming library to access databases. I just ran a simple JDBC connection and SQL SELECT test, and everything seems to work just as it does in Java.

MySQL show users - how to show the users in a MySQL database

MySQL users FAQ: How do I show MySQL users (How do I show user accounts I've created in a MySQL database)?

To show/list the users in a MySQL database, first log into your MySQL server as an administrative user, then run this MySQL query:

A MySQL database backup shell script

MySQL database backup FAQ: Can you share a Linux shell script that I can use to make a MySQL backup?

I currently have a collection of websites on several different servers (including GoDaddy and A2 Hosting web servers), so I was just spending some time trying to automate my MySQL database backups. To that end, I just created a MySQL shell script that I use on each Linux server to make my database backups, and I thought I'd share that script here.

Syndicate content