CentOS-based Mysql learning Supplement 2-using Shell to create a database, centosmysql
Article Source: CentOS-based Mysql learning Supplement 2-using Shell to create a database
For how to use the mysql database based on commands, see the "Instructions for using CentOS-based Mysql". This article only describes how to use the Shell script to create the database we want, the following is a Shell script for creating a database, which basically stores some mysql commands in the shell script.
#! /Bin/bash # Author: chisj # Time: 2015.7.22 # Describe: create Database # The username of mysql databaseUSER = "root" # The password of mysql databasePASS = "dragonwake" # The datebase name will be createdDATABASE = "SmartCare" mysql-u $ USER-p $ PASS <EOF>/dev/nullCREATE DATABASE $ DATABASEEOF
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
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.