Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/magepsycho/mysql-user-db-creator-bash-script
Script to create a mysql database, user and password with just a command
https://github.com/magepsycho/mysql-user-db-creator-bash-script
bash bash-script database-management mysql mysql-database password password-generator shell shell-script username
Last synced: 1 day ago
JSON representation
Script to create a mysql database, user and password with just a command
- Host: GitHub
- URL: https://github.com/magepsycho/mysql-user-db-creator-bash-script
- Owner: MagePsycho
- Created: 2018-03-23T08:36:39.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-11-25T16:39:32.000Z (almost 3 years ago)
- Last Synced: 2023-03-13T18:02:54.823Z (over 1 year ago)
- Topics: bash, bash-script, database-management, mysql, mysql-database, password, password-generator, shell, shell-script, username
- Language: Shell
- Homepage: https://blog.magepsycho.com/bash-script-create-mysql-database-user-optional-password/
- Size: 103 KB
- Stars: 24
- Watchers: 4
- Forks: 10
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# MySQL Database, User/Password Creator
This Script helps you to create a new MySQL database with specific user & password with just a single command.
## INSTALL
To install, simply download the script file and give it the executable permission.
```
curl -0 https://raw.githubusercontent.com/MagePsycho/mysql-user-db-creator-bash-script/master/src/mysql-db-user-creator.sh -o mysql-db-user-creator.sh
chmod +x mysql-db-user-creator.sh
```To make it system wide command
```
sudo mv mysql-db-user-creator.sh /usr/local/bin/mysql-db-user-creator
```## USAGE
### To display help
```
sudo ./mysql-db-user-creator.sh --help
```In General, basic usage
```
./mysql-db-user-creator.sh [--host=""] --database="" [--user=""] [--pass=""]
```
**Notes**:
- The only required parameter is `database` name.
- Default parameter values:| Parameter | Default Value |
|-|-|
| `host` | localhost |
| `user` | same as database name |
| `password` | randomly generated |And MySQL credentials for new db/user creation will be taken from the MySQL config file `~/.my.cnf`.
If you don't have one, you can simply create a `.my.cnf` file in home directory, with
```
[client]
host=localhost
user=[your-db-user]
password=[your-db-pass]
```
*If `~/.my.cnf` doesn't exist, you will be prompted for the root password. For an automated enviroment it's recommended to make use of MySQL config file.*### To Create Db along with specified User & Pass (By passing all parameters explicitly)
```
./mysql-db-user-creator.sh --host=192.168.1.55 --database=new-db-name --user=new-user --pass=some-strong-pass
```### To Create Db with User & Pass (By passing only required parameter)
```
./mysql-create-db-user.sh --database=bash_db2
```
*In this case default values will be used for missing parameters (see above)*## Output Sample
![MySQL DB, User/Password Creator Result](https://github.com/MagePsycho/mysql-user-db-creator-bash-script/raw/master/docs/mysql-user-db-creator-bash-script-result.png "Nginx Virtual Host Creator Result")
Screentshot - MySQL DB, User/Password Creator Result