<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ### 創建 MySQL 數據庫及用戶 MySQL 是一個使用廣泛的數據庫服務器,你肯定會在某些節點上安裝配置 MySQL 服務器。 本節將向你展示如何安裝配置 MySQL 服務器,以及如何為應用程序自動創建數據庫和用戶。 #### 準備工作 1. 如果你還沒有 MySQL 模塊,先創建一個: ``` # mkdir /etc/puppet/modules/mysql # mkdir /etc/puppet/modules/manifests # mkdir /etc/puppet/modules/files ``` 2. 使用如下內容創建 /etc/puppet/modules/mysql/manifests/server.pp 文件: ``` class mysql::server { package { "mysql-server": ensure =&gt; installed } service { "mysql": enable =&gt; true, ensure =&gt; running, require =&gt; Package["mysql-server"], } file { "/etc/mysql/my.cnf": owner =&gt; "mysql", group =&gt; "mysql", source =&gt; "puppet:///mysql/my.cnf", notify =&gt; Service["mysql"], require =&gt; Package["mysql-server"], } exec { "set-mysql-password": unless =&gt; "/usr/bin/mysqladmin -uroot -p${mysql_password} status", command =&gt; "/usr/bin/mysqladmin -uroot password ${mysql_ password}", require =&gt; Service["mysql"], } } ``` 3. 使用如下內容創建 /etc/puppet/modules/mysql/files/my.cnf 文件: ``` [client] port = 3306 socket = /var/run/mysqld/mysqld.sock [mysqld_safe] socket = /var/run/mysqld/mysqld.sock nice = 0 [mysqld] user = mysql socket = /var/run/mysqld/mysqld.sock port = 3306 datadir = /var/lib/mysql !includedir /etc/mysql/conf.d/ ``` 4. 添加如下代碼到 /etc/puppet/manifests/site.pp 文件: ``` $mysql_password = "secret" ``` 5. 運行 Puppet: ``` # puppet agent --test info: Retrieving plugin info: Caching catalog for cookbook.bitfieldconsulting.com info: Applying configuration version '1309448283' notice: /Stage[main]/Mysql::Server/Package[mysql-server]/ensure: ensure changed 'purged' to 'present' notice: /Stage[main]/Mysql::Server/File[/etc/mysql/my.cnf]/owner: owner changed 'root' to 'mysql' notice: /Stage[main]/Mysql::Server/File[/etc/mysql/my.cnf]/group: group changed 'root' to 'mysql' info: /Stage[main]/Mysql::Server/File[/etc/mysql/my.cnf]: Scheduling refresh of Service[mysql] info: /Stage[main]/Mysql::Server/File[/etc/mysql/my.cnf]: Scheduling refresh of Service[mysql] notice: /Stage[main]/Mysql::Server/Service[mysql]/enable: enable changed 'false' to 'true' notice: /Stage[main]/Mysql::Server/Service[mysql]: Triggered 'refresh' from 2 events notice: Finished catalog run in 61.78 seconds ``` #### 操作步驟 1. 添加如下代碼到 /etc/puppet/modules/mysql/manifests/server.pp 文件: ``` define db( $user, $password ) { include mysql::server exec { "create-${name}-db": unless =&gt; "/usr/bin/mysql -u${user} -p${password}${name}", command =&gt; "/usr/bin/mysql -uroot -p${mysql_password} -e \"create database ${name}; grant all on ${name}.* to ${user}@localhost identified by '$password'; flush privileges;\"", require =&gt; Service["mysql"], } } ``` 2. 添加如下代碼到一個節點: ``` mysql::server::db { "johnstest": user =&gt; "john", password =&gt; "johnstest", } ``` 3. 運行 Puppet: ``` # puppet agent --test info: Retrieving plugin info: Caching catalog for cookbook.bitfieldconsulting.com info: Applying configuration version '1309449259' notice: /Stage[main]//Node[cookbook]/Mysql::Server::Db[johnstest]/ Exec[create-johnstest-db]/returns: executed successfully notice: Finished catalog run in 1.61 seconds ``` 4. 檢查數據庫是否已經創建,以及用戶和權限的正確性: ``` # mysql -ujohn -pjohnstest johnstest Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 36 Server version: 5.1.41-3ubuntu12.10 (Ubuntu) Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql&gt; ``` #### 工作原理 mysql::server 類安裝 MySQL,并使用你在 site.pp 文件中設置的 root 用戶口令配置 MySQL。 名為 mysql::server::db 的 define 允許我們使用一個指定的名字創建數據庫, 以及一個能訪問此數據庫的相關的 MySQL 用戶。 例如,一個典型的 web 應用程序可能需要一個以應用程序命名的數據庫, 以及一個可以登錄數據庫的特定用戶名。 #### 更多用法 要創建多個數據庫,只需添加多個 mysql::server::db 實例: ``` mysql::server::db { [ "test1", "test2", "test3" ]: user => "john", password => "johnstest", } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看