1

Yugabyte,

is there a way I can create the YB DB and it's schema by running one script file with all the commands mentioned here (https://docs.yugabyte.com/latest/quick-start/explore/ysql/#docker)

theNewGuy
  • 23
  • 3

1 Answers1

0

You can execute queries with ysqlsh from the command line using -c, example we use that to create the database:

./bin/ysqlsh -c 'create database ybdemo;'

You can also execute sql scripts with ysqlsh using -f (https://docs.yugabyte.com/latest/admin/ysqlsh/#f-filename-file-filename), example:

./bin/ysqlsh -d ybdemo -f share/schema.sql

This will execute the schema.sql script into ybdemo database. And repeat that for every .sql file.

dh YB
  • 965
  • 3
  • 10
  • Thank you Dorian. This worked. Now I need to add these two below commands into a docker file and run itself when I create a container. docker exec -it yb1 /home/yugabyte/bin/ysqlsh -c 'create database ybdemo;' docker exec -it yb1 /home/yugabyte/bin/ysqlsh -d ybdemo -f share/schema.sql I also asked this here https://forum.yugabyte.com/t/create-yb-db-and-schemas-via-a-script-file/991/11 – theNewGuy Mar 17 '21 at 22:09