Articles related to real life scenarios involving java, frameworks and libraries configurations and salt-stack. The topics includes Core Java, Hibernate, Spring MySQL, Multithreading, Java NIO, jQuery, c3p0, Connection pooling, salt state, pillar, grain etc.

Thursday, August 13, 2015

Salt-stack mysql use root user from any host

8:33 AM Posted by Unknown No comments
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.

mysql-server:
  pkg:
    - installed
    - pkgs:
      - mysql-server
      - python-mysqldb
  service:
    - running
    - name: mysql
    - enable: True
    - require:
      - pkg: mysql-server
    - watch:
      - file: /etc/mysql/my.cnf
  mysql_user:
    - 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.

mysql-root-user-remote:
  mysql_user.present:
    - 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.




0 comments:

Post a Comment