Create MySQL Tables with Ansible Create MySQL Tables with Ansible sql sql

Create MySQL Tables with Ansible


With the mysql_db module you can import a MySQL file. So you can simply copy all 3 create statements into one singly text file and import it like this:

- mysql_db: name=my_db state=import target=/tmp/dump.sql.bz2

That example is taken from the above linked docs page, there are more tasks including one which shows you how to copy the file to the host before.



  • hosts: mysqltasks:
    • name: create a table in mysql_databasescommand: mysql -u root -p[root1234] testdb --skip-column-names --execute "create table test_table (Name varchar(255), EmpID INT NOT NULL)"

enter image description here