Create a database using Shell in CentOS
This article only describes how to use the Shell script to create the database we want. The Shell script for creating the database is provided below, which basically stores some mysql commands in the shell script.
[Plain] view plaincopy
- #! /Bin/bash
- # Author: chisj
- # Time: 2015.7.22
- # Describe: CreateDatabase
- # Theusernameofmysqldatabase
- USER = "root"
- # Thepasswordofmysqldatabase
- PASS = "dragonwake"
- # Thedatebasenamewillbecreated
- DATABASE = "SmartCare"
- Mysql-u $ USER-p $ PASS <EOF>/dev/null
- CREATEDATABASE $ DATABASE
- EOF
Several Notes
1. If the script is edited under windows and then executed under linux, this problem may occur.
You can also see the solution here. Use the command dos2unix to convert the windows file format to the linux (unix) file format.
# Dos2unix filename
Of course, the premise is that you need to install this command on your system. By default, this command is not installed on the system. You can use yum for installation.
# Yum install dos2unix
Here is a script in linux file format.
Create a mysql database using shell