尝试通过 Ansible 使用 WSREP API 安装 MySQL

尝试通过 Ansible 使用 WSREP API 安装 MySQL

我正在尝试使用 ansible 在 centos 7.7 上安装 galera 集群(带有 wsrep 5.7 的 mysql)。

我的规则文件:

  - name: Start the MySQL Daemon (first time)
  service:
    name: mysqld
    enabled: yes
    state: started

- name: Parse the logfile for temporary password
  command: grep 'temporary password' /var/log/mysqld.log
  register: pw_line

- name: Register the password
  set_fact:
    tmp_password: "{{ pw_line.stdout | regex_search(regexp, '\\1') }}"
  vars:
    regexp: ': (.+)$'

- name: Change temporary root password
  shell:
    cmd: mysql -u root --password="{{ tmp_password[0] }}" --connect-expired-password -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '{{ icinga2_mysql_root_password }}'; flush privileges; "

这将导致以下输出:

changed: [icinga2-db1.local] => {
    "changed": true,
    "cmd": "mysql -u root --password=\"fJuu)YTIA0<*\" --connect-expired-password -e \"ALTER USER 'root'@'localhost' IDENTIFIED BY 'S0me_P4$.worD'; flush privileges; \"",
    "delta": "0:00:00.021148",
    "end": "2020-02-23 18:23:10.323202",
    "invocation": {
        "module_args": {
            "_raw_params": "mysql -u root --password=\"fJuu)YTIA0<*\" --connect-expired-password -e \"ALTER USER 'root'@'localhost' IDENTIFIED BY 'S0me_P4$.worD'; flush privileges; \"",
            "_uses_shell": true,
            "argv": null,
            "chdir": null,
            "creates": null,
            "executable": null,
            "removes": null,
            "stdin": null,
            "stdin_add_newline": true,
            "strip_empty_ends": true,
            "warn": true
        }
    },
    "rc": 0,
    "start": "2020-02-23 18:23:10.302054",
    "stderr": "mysql: [Warning] Using a password on the command line interface can be insecure.",
    "stderr_lines": [
        "mysql: [Warning] Using a password on the command line interface can be insecure."
    ],
    "stdout": "",
    "stdout_lines": []
}

这似乎没问题,但不幸的是,之后我无法登录。我收到错误消息:

# mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

如果我重置(重新安装系统)并通过 mysql 登录到数据库并执行查询,一切正常。

我已经尝试了很多不同的方法来解决此问题(mysql_user,编辑 my.cnf,使用 mysqladmin),但都没有成功。

有人可以启发我吗?

编辑:我在命令行上尝试了以下操作:

# mysql -u root --password="#Uq.L*gcr0k." -e "ALTER USER 'root'@'localhost' IDENTIFIED BY 'S0me_P4$.worD'; flush privileges;"

这会导致上述同样的错误。但是,这是:

# mysql -u root --password="JRyAmO=p_7yq"
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.29

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'S0me_P4$.worD'; flush privileges;
Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

mysql>

有效。这是 mysql 5.7 中的错误吗?

相关内容