mysql-Datenbank mit einer Zeile in bash erstellen
Ist es möglich, eine leere Datenbank mit einer Befehlszeile in bash zu erstellen?
Meine Neulingsversuche sind fehlgeschlagen:
mysql -uroot $(create database mydatabase;)
Am Ende muss ich
mysql -uroot
create database mydatabase;
exit;
26
2 answers
@Nitrodists Antwort wird funktionieren, aber das Problem wird überentwickelt. MySQL command-line client unterstützt die sehr handlich -e
switch, like so:
mysql -uroot -e "create database 'foo'"
Sie können dort natürlich jedes gültige SQL ersetzen.
36
Author: Kromey,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2011-05-25 20:45:39
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2011-05-25 20:45:39
Laut MySQL-Dokumentation kann das mysql
Befehle von stdin
shell> mysql -uroot < script.sql > output.tab
Sie können Process Substitution verwenden, um dies zu erreichen:
shell> mysql -uroot <(echo "create database mydatabase;")
Oder Sie können es einfach normal an stdin
von mysql
weiterleiten:
shell> echo "create database mydatabase;" | mysql -uroot
Kann das nicht persönlich testen, aber ich denke, das sollte funktionieren.
Bearbeiten: Eine andere Option ist die Verwendung der Option -e
, die hier angegeben ist:
shell> mysql -uroot -e "create database mydatabase;"
14
Author: Nitrodist,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2015-02-09 22:07:03
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2015-02-09 22:07:03