<i id='Px8rc'><tr id='Px8rc'><dt id='Px8rc'><q id='Px8rc'><span id='Px8rc'><b id='Px8rc'><form id='Px8rc'><ins id='Px8rc'></ins><ul id='Px8rc'></ul><sub id='Px8rc'></sub></form><legend id='Px8rc'></legend><bdo id='Px8rc'><pre id='Px8rc'><center id='Px8rc'></center></pre></bdo></b><th id='Px8rc'></th></span></q></dt></tr></i><div id='Px8rc'><tfoot id='Px8rc'></tfoot><dl id='Px8rc'><fieldset id='Px8rc'></fieldset></dl></div>
  • <tfoot id='Px8rc'></tfoot>

    <small id='Px8rc'></small><noframes id='Px8rc'>

      <bdo id='Px8rc'></bdo><ul id='Px8rc'></ul>
  • <legend id='Px8rc'><style id='Px8rc'><dir id='Px8rc'><q id='Px8rc'></q></dir></style></legend>

      1. 在 ubuntu 上使用 ansible 安装 MySQL

        时间:2023-06-06
        <tfoot id='9fJUr'></tfoot>

        <small id='9fJUr'></small><noframes id='9fJUr'>

                <tbody id='9fJUr'></tbody>
                  <bdo id='9fJUr'></bdo><ul id='9fJUr'></ul>
                • <legend id='9fJUr'><style id='9fJUr'><dir id='9fJUr'><q id='9fJUr'></q></dir></style></legend>
                  <i id='9fJUr'><tr id='9fJUr'><dt id='9fJUr'><q id='9fJUr'><span id='9fJUr'><b id='9fJUr'><form id='9fJUr'><ins id='9fJUr'></ins><ul id='9fJUr'></ul><sub id='9fJUr'></sub></form><legend id='9fJUr'></legend><bdo id='9fJUr'><pre id='9fJUr'><center id='9fJUr'></center></pre></bdo></b><th id='9fJUr'></th></span></q></dt></tr></i><div id='9fJUr'><tfoot id='9fJUr'></tfoot><dl id='9fJUr'><fieldset id='9fJUr'></fieldset></dl></div>

                  本文介绍了在 ubuntu 上使用 ansible 安装 MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我在流浪的 ubuntu 上安装带有 ansible 的 MySQL 时遇到问题,

                  I have a problem installing MySQL with ansible on a vagrant ubuntu,

                  这是我的 MySQL 部分

                  This is my MySQL part

                  ---
                  - name: Install MySQL
                    apt:
                      name: "{{ item }}"
                    with_items:
                      - python-mysqldb
                      - mysql-server
                  
                  - name: copy .my.cnf file with root password credentials
                    template: 
                      src: templates/root/.my.cnf
                      dest: ~/.my.cnf
                      owner: root
                      mode: 0600
                  
                  - name: Start the MySQL service
                    service: 
                      name: mysql 
                      state: started
                      enabled: true
                  
                    # 'localhost' needs to be the last item for idempotency, see
                    # http://ansible.cc/docs/modules.html#mysql-user
                  - name: update mysql root password for all root accounts
                    mysql_user: 
                      name: root 
                      host: "{{ item }}" 
                      password: "{{ mysql_root_password }}" 
                      priv: "*.*:ALL,GRANT"
                    with_items:
                      - "{{ ansible_hostname }}"
                      - 127.0.0.1
                      - ::1
                      - localhost 
                  

                  我有这个错误

                  failed: [default] => (item=vagrant-ubuntu-trusty-64) => {"failed": true, "item": "vagrant-ubuntu-trusty-64"}
                  msg: unable to connect to database, check login_user and login_password are correct or ~/.my.cnf has the credentials
                  failed: [default] => (item=127.0.0.1) => {"failed": true, "item": "127.0.0.1"}
                  msg: unable to connect to database, check login_user and login_password are correct or ~/.my.cnf has the credentials
                  failed: [default] => (item=::1) => {"failed": true, "item": "::1"}
                  msg: unable to connect to database, check login_user and login_password are correct or ~/.my.cnf has the credentials
                  failed: [default] => (item=localhost) => {"failed": true, "item": "localhost"}
                  msg: unable to connect to database, check login_user and login_password are correct or ~/.my.cnf has the credentials
                  

                  我的 .my.cnf 是

                  my .my.cnf is

                  [client]
                  user=root
                  password={{ mysql_root_password }}
                  

                  当复制到服务器上时

                  [client]
                  user=root
                  password=root
                  

                  我不明白为什么,创建了 ~/.my.cnf

                  I don't understand why, ~/.my.cnf is created

                  项目 Github

                  谢谢

                  推荐答案

                  mysql-server 无头安装时,没有密码.因此,要使 .my.cnf 工作,它应该有一个空白的密码行.这是我为 .my.cnf 测试的内容:

                  When mysql-server is installed headlessly, there's no password. Therefore to make .my.cnf work, it should have a blank password line. Here's what I tested with for a .my.cnf:

                  [client]
                  user=root
                  password=
                  

                  .my.cnf 放在您的 vagrant 用户目录中也有点奇怪,因为它由 root 拥有并且只能作为 root 读取.

                  It's also slightly strange to put .my.cnf in your vagrant user directory as owned by root and only readable as root.

                  确保 .my.cnf 中的密码为空后,我能够在这四个上下文中正确设置 root 的密码.请注意,此后它无法运行,因为需要更新 .my.cnf,因此它无法通过幂等性测试.

                  After ensuring the password was blank in .my.cnf, I was able to properly set the password for root in those four contexts. Note that it fails to run after that, since .my.cnf would need to be updated, so it fails the idempotency test.

                  ansible mysql_user 模块页面上有一条注释,建议先写密码,然后然后.my.cnf 文件.如果你这样做,你需要一个 where 子句到 mysql_user 操作(可能在此之前有一个文件统计信息).

                  There's a note on the ansible mysql_user module page that suggests writing the password and then writing the .my.cnf file. If you do that, you need a where clause to the mysql_user action (probably with a file stat before that).

                  更优雅的是将 check_implicit_adminlogin_userlogin_password 一起使用.这真是幂等的.

                  Even more elegant is to use check_implicit_admin along with login_user and login_password. That's beautifully idempotent.

                  作为第三种方式,也许 check_implicit_admin 会更容易.

                  As a third way, perhaps check_implicit_admin makes it even easier.

                  这是我成功的剧本,展示了上述内容,并在几台新服务器上进行了测试.有点为此感到自豪.注意所有这些都不需要 .my.cnf.

                  Here's my successful playbook showing the above, tested with a few fresh servers. Kinda proud of this. Note .my.cnf is unnecessary for all of this.

                  ---
                  - hosts: mysql
                    vars:
                      mysql_root_password: fart
                    tasks:
                    - name: Install MySQL
                      apt: name={{ item }} update_cache=yes cache_valid_time=3600 state=present
                      sudo: yes
                      with_items:
                      - python-mysqldb
                      - mysql-server
                    #- name: copy cnf
                    #  copy: src=.my.cnf dest=~/.my.cnf owner=ubuntu mode=0644
                    #  sudo: yes
                    - name: Start the MySQL service
                      sudo: yes
                      service: 
                        name: mysql 
                        state: started
                        enabled: true
                    - name: update mysql root password for all root accounts
                      sudo: yes
                      mysql_user: 
                        name: root 
                        host: "{{ item }}" 
                        password: "{{ mysql_root_password }}"
                        login_user: root
                        login_password: "{{ mysql_root_password }}"
                        check_implicit_admin: yes
                        priv: "*.*:ALL,GRANT"
                      with_items:
                        - "{{ ansible_hostname }}"
                        - 127.0.0.1
                        - ::1
                        - localhost 
                  

                  (编辑-删除了 my.cnf)

                  (edit- removed my.cnf)

                  这篇关于在 ubuntu 上使用 ansible 安装 MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在节点 js mysql 查询函数中找到匿名函数之外 下一篇:使用 Ansible 任务运行 SELECT 查询

                  相关文章

                  最新文章

                  <legend id='OF0Kv'><style id='OF0Kv'><dir id='OF0Kv'><q id='OF0Kv'></q></dir></style></legend>
                • <small id='OF0Kv'></small><noframes id='OF0Kv'>

                      <tfoot id='OF0Kv'></tfoot>
                        <bdo id='OF0Kv'></bdo><ul id='OF0Kv'></ul>
                    1. <i id='OF0Kv'><tr id='OF0Kv'><dt id='OF0Kv'><q id='OF0Kv'><span id='OF0Kv'><b id='OF0Kv'><form id='OF0Kv'><ins id='OF0Kv'></ins><ul id='OF0Kv'></ul><sub id='OF0Kv'></sub></form><legend id='OF0Kv'></legend><bdo id='OF0Kv'><pre id='OF0Kv'><center id='OF0Kv'></center></pre></bdo></b><th id='OF0Kv'></th></span></q></dt></tr></i><div id='OF0Kv'><tfoot id='OF0Kv'></tfoot><dl id='OF0Kv'><fieldset id='OF0Kv'></fieldset></dl></div>