How to create MySQL tables using Ansible?

0 votes
How to create MySQL tables using Ansible?
Feb 4, 2019 in Ansible by Anvit
3,122 views

2 answers to this question.

0 votes

Hey @Anvit, you can use a module called mysql_db to add or remove databases from a remote host.

And then you can just copy all the create statement into a single file and import it. 

something like this:

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

answered Feb 4, 2019 by Diana
0 votes
---

- hosts: dbserver

  tasks:

   - name: create a table in mysqlDB

     command: mysql -u username -p yourpassword -h yourhostname dbname --skip-column-names --execute "create table if not exist tablename (name INT AUTO_INCREMENT, title VARCHAR(255) NOT NULL"
answered Mar 19, 2019 by Ankit Tyagi
Thanks @Ankit
M using same command :

    command: mysql -u root -p ********** bobdata --skip-column-names --execute "create table test789 (Name VARCHAR(25),ID int)"

But its giving syntax error . Kindly assist.

Hey @Shubhi, "int" should be in caps. Change the command to the following:

mysql -u root -p ********** bobdata --skip-column-names --execute "create table test789 (Name VARCHAR(25),ID INT)"

Related Questions In Ansible

0 votes
1 answer

devops , how to create user using ansible playbook

root doesn't need a password to switch ...READ MORE

answered Jul 16, 2018 in Ansible by Kalgi
• 2,620 points
200 views
0 votes
1 answer

How to create a docker container using Ansible playbook?

Hi@akhtar, You can use the docker_container module in ...READ MORE

answered 4 days ago in Ansible by MD
• 42,420 points
26 views
0 votes
1 answer

How to create a directory using Ansible?

Hi@akhtar, You can use the file module. To ...READ MORE

answered 2 days ago in Ansible by MD
• 42,420 points
21 views
0 votes
1 answer

How can I create a new user using ansible ploybook?

You're switching from the root user. Root ...READ MORE

answered Mar 29, 2018 in Ansible by DareDev
• 6,850 points
238 views
+13 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 26, 2018 in DevOps & Agile by DragonLord999
• 8,420 points
603 views
0 votes
1 answer
0 votes
1 answer

How to create a new encrpted file using Ansible Vault?

If you are creating a new file ...READ MORE

answered Jan 29, 2019 in Ansible by Kyraa
158 views
0 votes
1 answer