How to create MySQL tables using Ansible

0 votes
How to create MySQL tables using Ansible?
Feb 4, 2019 in Ansible by Anvit
8,032 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,680 points
1,135 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 Aug 8, 2020 in Ansible by MD
• 95,460 points
4,322 views
0 votes
1 answer

How to create a directory using Ansible?

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

answered Aug 10, 2020 in Ansible by MD
• 95,460 points
4,288 views
0 votes
1 answer

How to create a key pair on AWS using Ansible-Playbook?

Hi@akhtar, You can find the ec2_key module in ...READ MORE

answered Aug 12, 2020 in Ansible by MD
• 95,460 points
1,450 views
+15 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 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,035 views
+2 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
1,028 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP