Reputation: 3808
I am trying to automate some tasks for mysql docker container for that I am using a shell script. But I not able to pass/supply mysql commands after starting mysql server.
Below is my shell script.
#!/bin/bash
mysql.server start
mysql -u root
show databases;
All steps are works as expected else last one 'show databases;' am not getting how to pass 'show databases;' command after mysql server starts. I am on a MAC machine, same behaviour happens on my ubuntu 14.04 container.
below is output on my console.
Upvotes: 0
Views: 72
Reputation: 1190
Please try:
mysql -uUSER -pPASSWORD DBNAME -e 'show databases;'
USER is your user PASSWORD is your password -e switch is used to fire commands to mysql via shell
A sample output:
User@Host:~> mysql -uUSER -pPASSWORD DBNAME -e 'show databases ;'
+--------------------+
| Database |
+--------------------+
| information_schema |
| mdpdb |
| mdpdb6 |
| mysql |
+--------------------+
Upvotes: 1