我的saltstack mysql安装有什么问题?

时间:2016-02-14 12:08:09

标签: mysql salt-stack

我也是一个saltstack新手和mysql新手......: - /我试图在Ubuntu 14上安装my-sql。我收到了以下错误

enter image description here

我使用以下sls文件

mysql_package:
  pkg.installed:
    - name: mysql-server

mysql_conf:
  file.managed:
    - name: /etc/my.cnf
    - source: salt://mysql/files/my.cnf
    - user: root
    - group: root
    - mode: 0644
    - require:
      - pkg: mysql_package

mysql_service:
  service:
    - name: mysqld
    - running
    - enable: True
    - require:
      - pkg: mysql_conf
    - watch:
      - pkg: mysql_conf

# required packages start
server_pkgs:
  pkg:
    - installed
    - pkgs:
      - python-dev
    - refresh: True

mysql_python_pkgs:
  pkg.installed:
    - pkgs:
      - libmysqlclient-dev
      - mysql-client
      - python-mysqldb
    - require:
      - pkg: server_pkgs

python-pip:
  pkg:
    - installed
    - refresh: False

mysql:
  pip.installed:
    - require:
      - pkg: python-pip
      - pkg: mysql_python_pkg
# required package end

stg_databases:
  mysql_database.present:
    - name: stagingdb
    - require:
      - pkg: mysql
      - service: mysql_service

first_db_user:
  mysql_user.present:
    - name: stg-admin
    - password: "pass4admin"
    - host: '%'
    - connection_charset: utf8
    - saltenv:
      - LC_ALL: "en_US.utf8"
    - require:
      - mysql_database: stg_databases


create_first_table:
  mysql_query.run:
    - database: stagingdb
    - query: "create table first_table(id INT NOT NULL AUTO_INCREMENT, name VARCHAR(100) NOT NULL, PRIMARY KEY ( id ));"
    - output:   "/tmp/create_first_table.txt"
    - require:
      - mysql_database: stg_databases


first_table_grants:
  mysql_grants.present:
    - grant: all privileges
    - database: stagingdb.*
    - user: stg-admin
    - host: '%'
    - require:
      - mysql_user: first_db_user

并使用以下conf文件

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

遇到以下链接MySQL - ERROR 1045 - Access denied,这不是我想做的事情......

猜测my.cnf和sls文件中定义的用户之间是否存在关联,这是不正确的?

2 个答案:

答案 0 :(得分:0)

运行此状态时哪里有错误?

如果你跑:

{{1}}

这将为您提供有关正在运行的盐的大量有用信息。 root用户是否仍然可用?你能登录并查看该用户是否真的被创建了吗?

答案 1 :(得分:0)

这是显而易见的Mysql GRANT问题,您无需进行调试。这意味着你在授予用户方面犯了一些错误。只需查看文档:{​​{3}}

即可

mysql_user.present不授予用户权限。你需要 mysql_grants.present 和mysql_user.present。令人困惑的部分:mysql_grants.present没有设置密码; mysql_user.present设置密码但不授予数据库权限。

first_db_user:
  mysql_user.present:
    - name: stg-admin
    - password: "pass4admin"
    - host: '%'
    - connection_charset: utf8
    - saltenv:
      - LC_ALL: "en_US.utf8"
    - require:
      - mysql_database: stg_databases

grant_my_first_db_user:
  mysql_grants.present:
    - grant: select,insert,update
    - database: stagingdb
    - user: stg-admin
    - host: localhost

而saltstack mysql公式证实了这一点。

https://docs.saltstack.com/en/latest/ref/states/all/salt.states.mysql_user.html