Wednesday, 10 August 2016

Salt-stack mysql use root user from any host

I recently had a problem while installing mysql on a server using salt-stack.

The scenario is that there is a server where I install mysql and other servers should be able to access it. Now these are ec2 instances and the security group is setup such a way that only server having certain security group can access the mysql server. So even if I open mysql for any host, There would not be any security issues.

The problem was that I was not able to login to root user from any other server because the root user login was only allowed from the localhost if I do the following.

    - installed
    - pkgs:
      - mysql-server
      - python-mysqldb
    - running
    - name: mysql
    - enable: True
    - require:
      - pkg: mysql-server
    - watch:
      - file: /etc/mysql/my.cnf
    - present
    - name: root
    - password: {{ pillar['mysql']['server']['root_password'] }}
    - require:
      - service: mysql
So what I had to do for the servers to login as root user into mysql database from any host including localhost is to add another user.preset for root again with % as host.

    - name: root
    - host: '%'
    - password: {{ pillar['mysql']['server']['root_password'] }}
    - connection_user: root
    - connection_pass: {{ pillar['mysql']['server']['root_password'] }}
    - connection_charset: utf8
    - saltenv:
      - LC_ALL: "en_US.utf8"
    - require:
      - service: mysql
This works for any user which should be accessible from any host including localhost.
Any questions or suggestions are welcome.

Ideaapplied Technologies provides comprehensive QA services. Visit us at to know more about our services

No comments:

Post a Comment