Home
PHP
Tech Tube
MySQL
Linux
CSS&HTML
JavaScript

Create MySQL table

This script creates a new table related to the next month. It could be useful for projects that store the data from each month in a different table. You could also modify it to execute any query.
# Bash script to execute query:
#!/bin/bash

db_host="your-host"
db_name="your-database"
db_user="your-mysql-user"
db_pass="your-mysql-pass"

bkp_date=$(date --date='+1 month' +"%Y%m");
query="CREATE TABLE IF NOT EXISTS notes_$bkp_date (id INT(10) UNSIGNED AUTO_INCREMENT, data VARCHAR(255), PRIMARY KEY(id)) ENGINE = InnoDB"

/usr/bin/mysql --user=$db_user --password=$db_pass --database=$db_name --execute="$query"
Download...