www.icesr.com
IT运维工程师的摇篮

分析mysql5.6镜像中的entrypoint.sh脚本

今天玩了下mysql的镜像,看到有个entrypoint.sh。

大概看了看发现里面的好多写法确实不常见,想仔细分析一下,发现网上已经有了相对应的文章写的很详细,这里就转载一下。

转自:http://www.cnblogs.com/ivictor/p/4832832.html

entrypoint.sh很耐人寻味,这个文件相当详实,涉及了Mysql如何初始化,如何设置密码,如何启动服务等关键问题。

今天花费了大半天来分析这个脚本,果然是受益匪浅。

脚本及分析结果如下:

复制代码
#!<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">/</span>bin<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">/</span><span style="margin:0px; padding:0px; line-height:1.5">bash
</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">set</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5">e

# </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">if</span> command starts <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">with</span> an <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">option</span><span style="margin:0px; padding:0px; line-height:1.5">, prepend mysqld
</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">if</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)"> &quot;${1:0:1}&quot; = '-' </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span>; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">then</span>
    <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">set</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">--</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)"> mysqld &quot;$@&quot;</span>
<span style="margin:0px; padding:0px; line-height:1.5">fi

</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">if</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)"> &quot;$1&quot; = 'mysqld' </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span>; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">then</span><span style="margin:0px; padding:0px; line-height:1.5">
    # Get config
    DATADIR</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">=</span>&quot;$(&quot;$@&quot; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">--</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">verbose --help 2&gt;/dev/null | awk '$1 == &quot;datadir&quot; { print $2; exit }')&quot;</span>

    <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">if</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)"> ! -d &quot;$DATADIR/mysql&quot; </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span>; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">then</span>
        <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">if</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)"> -z &quot;$MYSQL_ROOT_PASSWORD&quot; -a -z &quot;$MYSQL_ALLOW_EMPTY_PASSWORD&quot; </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span>; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">then</span><span style="margin:0px; padding:0px; line-height:1.5">
            echo </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">&gt;&amp;</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>2</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">error: database is uninitialized and MYSQL_ROOT_PASSWORD not set</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5">
            echo </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">&gt;&amp;</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>2</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">  Did you forget to add -e MYSQL_ROOT_PASSWORD=... ?</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span>
            <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">exit</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span><span style="margin:0px; padding:0px; line-height:1.5">
        fi

        mkdir </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5">p &quot;$DATADIR&quot;
        chown </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5">R mysql:mysql &quot;$DATADIR&quot;

        echo </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">Running mysql_install_db</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5">
        mysql_install_db </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">--</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">user=mysql --datadir=&quot;$DATADIR&quot; --rpm --keep-my-cnf</span>
        echo <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">Finished mysql_install_db</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5">

        mysqld </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">--</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">user=mysql --datadir=&quot;$DATADIR&quot; --skip-networking &amp;</span>
        pid<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">=</span><span style="margin:0px; padding:0px; line-height:1.5">&quot;$!&quot;

        mysql</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">=</span>( mysql <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">--</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">protocol=socket -uroot )</span>

        <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">for</span> i <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">in</span> {<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>30</strong></span>..<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>0</strong></span><span style="margin:0px; padding:0px; line-height:1.5">}; do
            </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">if</span> echo <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">SELECT 1</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">|</span> &quot;${mysql<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">@</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span>}&quot; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">&amp;&gt;</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">/</span>dev<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">/</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">null</span>; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">then</span>
                <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">break</span><span style="margin:0px; padding:0px; line-height:1.5">
            fi
            echo </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">MySQL init process in progress...</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5">
            sleep </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span><span style="margin:0px; padding:0px; line-height:1.5">
        done
        </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">if</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)"> &quot;$i&quot; = 0 </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span>; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">then</span><span style="margin:0px; padding:0px; line-height:1.5">
            echo </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">&gt;&amp;</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>2</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">MySQL init process failed.</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span>
            <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">exit</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span><span style="margin:0px; padding:0px; line-height:1.5">
        fi

        # sed </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">is</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">for</span> https:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">//</span>bugs.mysql.com<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">/</span>bug.php?id<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">=</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>20545</strong></span><span style="margin:0px; padding:0px; line-height:1.5">
        mysql_tzinfo_to_sql </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">/</span>usr<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">/</span>share<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">/</span>zoneinfo <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">|</span> sed <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">s/Local time zone must be set--see zic manual page/FCTY/</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">|</span> &quot;${mysql<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">@</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span><span style="margin:0px; padding:0px; line-height:1.5">}&quot; mysql

        &quot;${mysql</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">@</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span>}&quot; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">&lt;&lt;-</span><span style="margin:0px; padding:0px; line-height:1.5">EOSQL
            </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">--</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)"> What's done in this file shouldn't be replicated</span>
            <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">--</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">  or products like mysql-fabric won't work</span>
            <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">SET</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,0)"><strong>@@SESSION</strong></span>.SQL_LOG_BIN<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">=</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>0</strong></span><span style="margin:0px; padding:0px; line-height:1.5">;
            </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">DELETE</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">FROM</span> mysql.<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,255)">user</span><span style="margin:0px; padding:0px; line-height:1.5"> ;
            </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">CREATE</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,255)">USER</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">root</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span>@<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">%</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span> IDENTIFIED <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">BY</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">${MYSQL_ROOT_PASSWORD}</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5"> ;
            </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">GRANT</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">ALL</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">ON</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">*</span>.<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">*</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">TO</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">root</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span>@<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">%</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">WITH</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">GRANT</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">OPTION</span><span style="margin:0px; padding:0px; line-height:1.5"> ;
            </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">DROP</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">DATABASE</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">IF</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">EXISTS</span><span style="margin:0px; padding:0px; line-height:1.5"> test ;
            FLUSH </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">PRIVILEGES</span><span style="margin:0px; padding:0px; line-height:1.5"> ;
        EOSQL

        </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">if</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)"> ! -z &quot;$MYSQL_ROOT_PASSWORD&quot; </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span>; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">then</span><span style="margin:0px; padding:0px; line-height:1.5">
            mysql</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">&#43;=</span>( <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5">p&quot;${MYSQL_ROOT_PASSWORD}&quot; )
        fi

        </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">if</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)"> &quot;$MYSQL_DATABASE&quot; </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span>; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">then</span><span style="margin:0px; padding:0px; line-height:1.5">
            echo &quot;</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">CREATE</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">DATABASE</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">IF</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">NOT</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">EXISTS</span> /`$MYSQL_DATABASE/` ;&quot; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">|</span> &quot;${mysql<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">@</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span><span style="margin:0px; padding:0px; line-height:1.5">}&quot;
            mysql</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">&#43;=</span><span style="margin:0px; padding:0px; line-height:1.5">( &quot;$MYSQL_DATABASE&quot; )
        fi

        </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">if</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)"> &quot;$MYSQL_USER&quot; -a &quot;$MYSQL_PASSWORD&quot; </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span>; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">then</span><span style="margin:0px; padding:0px; line-height:1.5">
            echo &quot;</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">CREATE</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,255)">USER</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">&quot;$MYSQL_USER&quot;</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span>@<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">%</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span> IDENTIFIED <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">BY</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">&quot;$MYSQL_PASSWORD&quot;</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span> ;&quot; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">|</span> &quot;${mysql<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">@</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span><span style="margin:0px; padding:0px; line-height:1.5">}&quot;

            </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">if</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)"> &quot;$MYSQL_DATABASE&quot; </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span>; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">then</span><span style="margin:0px; padding:0px; line-height:1.5">
                echo &quot;</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">GRANT</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">ALL</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">ON</span> /`&quot;$MYSQL_DATABASE&quot;/`.<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">*</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">TO</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">&quot;$MYSQL_USER&quot;</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span>@<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">%</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span> ;&quot; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">|</span> &quot;${mysql<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">@</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span><span style="margin:0px; padding:0px; line-height:1.5">}&quot;
            fi

            echo </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">FLUSH PRIVILEGES ;</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">|</span> &quot;${mysql<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">@</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span><span style="margin:0px; padding:0px; line-height:1.5">}&quot;
        fi

        echo
        </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">for</span> f <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">in</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">/</span>docker<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span>entrypoint<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span>initdb.d<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">/*</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">; do
            case &quot;$f&quot; in
                *.sh)  echo &quot;$0: running $f&quot;; . &quot;$f&quot; ;;
                *.sql) echo &quot;$0: running $f&quot;; &quot;${mysql[@]}&quot; &lt; &quot;$f&quot; &amp;&amp; echo ;;
                *)     echo &quot;$0: ignoring $f&quot; ;;
            esac
            echo
        done

        if ! kill -s TERM &quot;$pid&quot; || ! wait &quot;$pid&quot;; then
            echo &gt;&amp;2 'MySQL init process failed.'
            exit 1
        fi

        echo
        echo 'MySQL init process done. Ready for start up.'
        echo
    fi

    chown -R mysql:mysql &quot;$DATADIR&quot;
fi

exec &quot;$@&quot;</span>
复制代码

说明如下:

1> set -e, Manual文档的说明如下:

Exit immediately if a pipeline (which may consist of a single simple command), a subshell com‐

mand enclosed in parentheses, or one of the commands executed as part of a command list

enclosed by braces (see SHELL GRAMMAR above) exits with a non-zero status.

这句语句告诉bash如果任何语句的执行结果不是true则应该退出。这样的好处是防止错误像滚雪球般变大导致一个致命的错误,而这些错误本应该在之前就被处理掉。

关于set -e的利弊,可参考一下两篇博客

(1)Unix/Linux 脚本中 “set -e” 的作用

(2)linux中的set命令: "set -e" 与 "set -o pipefail"

2> 

<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">if</span> [ <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)">&quot;</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)">${1:0:1}</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)">&quot;</span> = <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)">'</span> ]; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">then</span><span style="margin:0px; padding:0px; line-height:1.5">
    set </span>-- mysqld <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)">&quot;</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)">$@</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)">&quot;</span>
<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">fi</span>

用于判断该脚本后面的参数是否以“-”开始,它考虑的是启动mysqld是带参数的情况,如果有的话,就将mysqld和参数作为变量存到$@中。

关于set –,Manual文档的说明如下:

If no arguments follow this option, then the positional parameters are unset. Otherwise, the

positional parameters are set to the args, even if some of them begin with a -.

验证如下:

首先构造脚本

复制代码
<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">root@localhost ~</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span># cat <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>4</strong></span><span style="margin:0px; padding:0px; line-height:1.5">.sh 
#!</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">/</span>bin<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">/</span><span style="margin:0px; padding:0px; line-height:1.5">bash
</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">if</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)"> &quot;${1:0:1}&quot; = '-' </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span>; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">then</span>
        <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">set</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">--</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)"> mysqld &quot;$@&quot;</span>
<span style="margin:0px; padding:0px; line-height:1.5">fi
echo </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">$@: </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5">&quot;$@&quot;
echo </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">$1: </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span>&quot;$<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span>&quot;
复制代码

加入参数进行验证

复制代码
<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">root@localhost ~</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span># sh <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>4</strong></span>.sh <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>123</strong></span><span style="margin:0px; padding:0px; line-height:1.5">
$@: </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>123</strong></span><span style="margin:0px; padding:0px; line-height:1.5">
$</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span>: <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>123</strong></span>
<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">root@localhost ~</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span># sh <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>4</strong></span>.sh <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>123</strong></span><span style="margin:0px; padding:0px; line-height:1.5">
$@: mysqld </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>123</strong></span><span style="margin:0px; padding:0px; line-height:1.5">
$</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span><span style="margin:0px; padding:0px; line-height:1.5">: mysqld
</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">root@localhost ~</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span># sh <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>4</strong></span>.sh <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>123</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>456</strong></span><span style="margin:0px; padding:0px; line-height:1.5">
$@: mysqld </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>123</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>456</strong></span><span style="margin:0px; padding:0px; line-height:1.5">
$</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span>: mysqld
复制代码

补充一点:关于$@与$*的区别,$@指每个位置参数参数都是一个独立的""引用字串,这就意味着参数被完整地传递,而$*则指所有位置参数只被一个""引用,相当于一个参数。

3>

<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">if</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)"> &quot;$1&quot; = 'mysqld' </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span>; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">then</span>

如果$1为mysqld,则执行下面的代码,如果不是,则执行该脚本最后一行的exec "$@"。

注意:Dockerfile中的CMD命令为 ["mysqld"],CMD命令其实就是ENTRYPOINT的参数,譬如如果ENTRYPOINT命令为ls,则CMD命令为-l,则实现的效果就是ls -l,

在启动容器时,自己输入的命令其实是覆盖CMD参数的,具体在本例中,就意味着在启动容器时,自已输入的命令只有在三种情况下才会启动mysqld服务:一、mysqld(相当于CMD参数)。二、以“-”开始的参数列表,这样上述2中的脚本才会判断为真。三、mysqld + 以“-”开始的参数列表。除此之外,其它所有的命令都不会启动mysql server服务,而是直接执行自己输入的命令。

4>

 DATADIR<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">=</span>&quot;$(&quot;$@&quot; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">--</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">verbose --help 2&gt;/dev/null | awk '$1 == &quot;datadir&quot; { print $2; exit }')&quot;</span>

获取mysql server的数据目录,倘若我们没有输入任何以“-”开始的参数列表,则$@为mysqld,上述命令执行的结果如下:

<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">root@localhost ~</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span># mysqld <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">--</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">verbose --help 2&gt;/dev/null | awk '$1 == &quot;datadir&quot; { print $2; exit }'</span>
<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">/</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,255)">var</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">/</span>lib<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">/</span>mysql<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">/</span>

5> 

 <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">if</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)"> ! -d &quot;$DATADIR/mysql&quot; </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span>; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">then</span>

如果存在/var/lib/mysql/mysql目录存在文件,则跳过中间的步骤,直接执行chown -R mysql:mysql "$DATADIR",它这里判断的一个依据是,如果/var/lib/mysql/mysql存在文件,则代表mysql server已经安装,这时就无需安装(当然,如果强行安装的 话,可能会覆盖),直接将其属主修改为mysql用户。很多童鞋可能好奇,不是新建的镜像么?这个目录怎么可能存在呢?我当初也存在这样的疑惑,后来验证了一番,发现如果将宿主机的目录直接挂载到镜像的/var/lib/mysql下,则启动mysql镜像时,没有进行mysql的初始化,设置root密码等,直接启动mysql服务,具体如下:

复制代码
<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">root@localhost ~</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span># docker run <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span>v <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">/</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,255)">var</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">/</span>lib<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">/</span>mysql:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">/</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,255)">var</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">/</span>lib<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">/</span><span style="margin:0px; padding:0px; line-height:1.5">mysql mysql
</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>2015</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>09</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>24</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>02</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>08</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>05</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>0</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">Note</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span> mysqld (mysqld <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>5.6</strong></span>.<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>26</strong></span>) starting <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">as</span> process <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span><span style="margin:0px; padding:0px; line-height:1.5"> ...
</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>2015</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>09</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>24</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>02</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>08</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>05</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">Note</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span> Plugin <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">FEDERATED</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">is</span><span style="margin:0px; padding:0px; line-height:1.5"> disabled.
</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>2015</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>09</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>24</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>02</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>08</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>05</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">Note</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span> InnoDB: Using atomics <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">to</span> ref <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,255)">count</span><span style="margin:0px; padding:0px; line-height:1.5"> buffer pool pages
</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>2015</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>09</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>24</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>02</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>08</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>05</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">Note</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span> InnoDB: The InnoDB memory heap <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">is</span><span style="margin:0px; padding:0px; line-height:1.5"> disabled
</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>2015</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>09</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>24</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>02</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>08</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>05</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">Note</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span> InnoDB: Mutexes <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">and</span> rw_locks <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">use</span><span style="margin:0px; padding:0px; line-height:1.5"> GCC atomic builtins
</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>2015</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>09</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>24</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>02</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>08</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>05</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">Note</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span> InnoDB: Memory barrier <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">is</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">not</span><span style="margin:0px; padding:0px; line-height:1.5"> used
</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>2015</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>09</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>24</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>02</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>08</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>05</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">Note</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span> InnoDB: Compressed tables <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">use</span> zlib <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1.2</strong></span>.<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>7</strong></span>
<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>2015</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>09</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>24</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>02</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>08</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>05</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">Note</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span><span style="margin:0px; padding:0px; line-height:1.5"> InnoDB: Using Linux native AIO
</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>2015</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>09</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>24</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>02</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>08</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>05</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">Note</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span><span style="margin:0px; padding:0px; line-height:1.5"> InnoDB: Using CPU crc32 instructions
</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>2015</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>09</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>24</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>02</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>08</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>05</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">Note</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span> InnoDB: Initializing buffer pool, size <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">=</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>128</strong></span><span style="margin:0px; padding:0px; line-height:1.5">.0M
</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>2015</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>09</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>24</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>02</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>08</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>05</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">Note</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span> InnoDB: Completed initialization <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">of</span><span style="margin:0px; padding:0px; line-height:1.5"> buffer pool
</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>2015</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>09</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>24</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>02</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>08</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>05</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">Note</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span> InnoDB: Highest supported <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">file</span> format <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">is</span><span style="margin:0px; padding:0px; line-height:1.5"> Barracuda.
</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>2015</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>09</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>24</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>02</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>08</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>06</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">Note</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span> InnoDB: <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>128</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">rollback</span><span style="margin:0px; padding:0px; line-height:1.5"> segment(s) are active.
</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>2015</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>09</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>24</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>02</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>08</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>06</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">Note</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span> InnoDB: Waiting <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">for</span> purge <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">to</span><span style="margin:0px; padding:0px; line-height:1.5"> start
</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>2015</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>09</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>24</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>02</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>08</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>06</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">Note</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span> InnoDB: <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>5.6</strong></span>.<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>26</strong></span> started; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,255)">log</span> sequence <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">number</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1697388</strong></span>
<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>2015</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>09</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>24</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>02</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>08</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>06</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">Note</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span> Server hostname (bind<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span>address): <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">*</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span>; port: <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>3306</strong></span>
<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>2015</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>09</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>24</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>02</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>08</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>06</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">Note</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span> IPv6 <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">is</span><span style="margin:0px; padding:0px; line-height:1.5"> available.
</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>2015</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>09</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>24</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>02</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>08</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>06</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">Note</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span>   <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">::</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span> resolves <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">to</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">::</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5">;
</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>2015</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>09</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>24</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>02</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>08</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>06</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">Note</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span> Server socket created <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">on</span> IP: <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">::</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5">.
</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>2015</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>09</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>24</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>02</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>08</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>06</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">Warning</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">user</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span> entry <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">root@localhost.localdomain</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span> ignored <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">in</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">--</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">skip-name-resolve mode.</span>
<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>2015</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>09</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>24</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>02</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>08</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>06</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">Warning</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">user</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span> entry <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">@localhost.localdomain</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span> ignored <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">in</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">--</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">skip-name-resolve mode.</span>
<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>2015</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>09</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>24</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>02</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>08</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>06</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">Warning</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">proxies_priv</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span> entry <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">@ root@localhost.localdomain</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span> ignored <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">in</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">--</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">skip-name-resolve mode.</span>
<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>2015</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>09</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>24</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>02</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>08</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>06</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">Note</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span> Event Scheduler: Loaded <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>0</strong></span><span style="margin:0px; padding:0px; line-height:1.5"> events
</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>2015</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>09</strong></span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>24</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>02</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>08</strong></span>:<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>06</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">Note</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span> mysqld: ready <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">for</span><span style="margin:0px; padding:0px; line-height:1.5"> connections.
Version: </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">5.6.26</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span>  socket: <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">/var/run/mysqld/mysqld.sock</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span>  port: <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>3306</strong></span>  MySQL Community Server (GPL)
复制代码

而先前的启动过程则涉及到初始化,启动,显性设置root密码等。

将宿主机的var/lib/mysql/挂载给容器后,我们再来看看宿主机上该目录的权限。

复制代码
<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">root@localhost ~</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span># ll <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">/</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,255)">var</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">/</span>lib<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">/</span>mysql<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">/</span><span style="margin:0px; padding:0px; line-height:1.5">
total </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>110604</strong></span>
<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span>rw<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span>rw<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">--</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">-- 1 polkitd ssh_keys       56 Sep 14 15:46 auto.cnf</span>
drwx<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">--</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">---- 2 polkitd ssh_keys      131 Sep 14 16:03 db1</span>
drwx<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">--</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">---- 2 polkitd ssh_keys      131 Sep 14 16:03 db2</span>
drwx<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">--</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">---- 2 polkitd ssh_keys       55 Sep 14 16:02 db3</span>
<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span>rw<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span>rw<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">--</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">-- 1 polkitd ssh_keys 12582912 Sep 24 10:08 ibdata1</span>
<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span>rw<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span>rw<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">--</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">-- 1 polkitd ssh_keys 50331648 Sep 24 10:08 ib_logfile0</span>
<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span>rw<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span>rw<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">--</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">-- 1 polkitd ssh_keys 50331648 Sep 14 15:45 ib_logfile1</span>
drwx<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">--</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">---- 2 polkitd ssh_keys     4096 Sep 23 14:18 mysql</span>
drwx<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">--</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">---- 2 polkitd ssh_keys     4096 Sep 22 13:47 performance_schema</span>
复制代码

属主为polkitd,属组为ssh_keys。

此时,需显性将/var/lib/mysql的属主和属组恢复为mysql,即chown -R mysql:mysql /var/lib/mysql/,不然,宿主机的mysql服务将无法启动。

 

6> 

 <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">if</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)"> -z &quot;$MYSQL_ROOT_PASSWORD&quot; -a -z &quot;$MYSQL_ALLOW_EMPTY_PASSWORD&quot; </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span>; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">then</span><span style="margin:0px; padding:0px; line-height:1.5">
            echo </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">&gt;&amp;</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>2</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">error: database is uninitialized and MYSQL_ROOT_PASSWORD not set</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5">
            echo </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">&gt;&amp;</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>2</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">  Did you forget to add -e MYSQL_ROOT_PASSWORD=... ?</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span>
            <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">exit</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span><span style="margin:0px; padding:0px; line-height:1.5">
 fi</span>

设置mysql的root账户的密码,其中-z判断是否为空字符串,-a 两个条件同时满足,才为true。从这里也可以看出来,随意给MYSQL_ALLOW_EMPTY_PASSWORD赋一个值,都可以实现无密码登录。

7>

复制代码
        mkdir <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5">p &quot;$DATADIR&quot;
        chown </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5">R mysql:mysql &quot;$DATADIR&quot;

        echo </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">Running mysql_install_db</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5">
        mysql_install_db </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">--</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">user=mysql --datadir=&quot;$DATADIR&quot; --rpm --keep-my-cnf</span>
        echo <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">Finished mysql_install_db</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5">

        mysqld </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">--</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">user=mysql --datadir=&quot;$DATADIR&quot; --skip-networking &amp;</span>
        pid<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">=</span>&quot;$!&quot;
复制代码

创建/var/lib/mysql,同时将其属主和属组设置为mysql,然后初始化数据库,最后用mysqld命令启动数据库。$!指的是Shell最后运行的后台Process的PID。

8> 

复制代码
        mysql<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">=</span>( mysql <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">--</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">protocol=socket -uroot )</span>

        <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">for</span> i <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">in</span> {<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>30</strong></span>..<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>0</strong></span><span style="margin:0px; padding:0px; line-height:1.5">}; do
            </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">if</span> echo <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">SELECT 1</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">|</span> &quot;${mysql<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">@</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span>}&quot; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">&amp;&gt;</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">/</span>dev<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">/</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">null</span>; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">then</span>
                <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">break</span><span style="margin:0px; padding:0px; line-height:1.5">
            fi
            echo </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">MySQL init process in progress...</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5">
            sleep </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span><span style="margin:0px; padding:0px; line-height:1.5">
        done
        </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">if</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)"> &quot;$i&quot; = 0 </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span>; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">then</span><span style="margin:0px; padding:0px; line-height:1.5">
            echo </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">&gt;&amp;</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>2</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">MySQL init process failed.</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span>
            <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">exit</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span><span style="margin:0px; padding:0px; line-height:1.5">
        fi</span>
复制代码

这段代码主要是利用mysql客户端测试mysql服务是否启动。这里面利用括号()构造mysql变量的方式挺有意思的,以前没有见过。特意验证了一下:

<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">root@localhost ~</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span># mysql<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">=</span>( mysql <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">--</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">protocol=socket -uroot )</span>
<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">root@localhost ~</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span><span style="margin:0px; padding:0px; line-height:1.5"># echo ${mysql}
mysql
</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">root@localhost ~</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span># echo ${mysql<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">@</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span><span style="margin:0px; padding:0px; line-height:1.5">}
mysql </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">--</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">protocol=socket -uroot</span>

这段代码给了30s的时间来判断mysql服务是否已启动,如果启动了,则退出循环,如果没有启动,循环结束后,变量i的值为0,通过后续的if语句,屏幕输出“MySQL init process failed”。

这里判断mysql服务是否启动的方式蛮有意思的,

复制代码
<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">root@localhost ~</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span># mysql<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">=</span>( mysql <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">--</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">protocol=socket -uroot )</span>
<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">root@localhost ~</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span># echo <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">SELECT 1</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">|</span> &quot;${mysql<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">@</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span><span style="margin:0px; padding:0px; line-height:1.5">}&quot; 
</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span>
<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span>
<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">root@localhost ~</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span><span style="margin:0px; padding:0px; line-height:1.5"># mysql
Welcome </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">to</span> the MySQL monitor.  Commands <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">end</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">with</span> ; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">or</span><span style="margin:0px; padding:0px; line-height:1.5"> /g.
Your MySQL connection id </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">is</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>11</strong></span><span style="margin:0px; padding:0px; line-height:1.5">
Server version: </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>5.6</strong></span>.<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>26</strong></span><span style="margin:0px; padding:0px; line-height:1.5"> MySQL Community Server (GPL)
</span><span style="margin:0px; padding:0px; line-height:1.5">mysql</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">&gt;</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">select</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span><span style="margin:0px; padding:0px; line-height:1.5">;
</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">&#43;</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">--</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">-&#43;</span>
<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">|</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">|</span>
<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">&#43;</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">--</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">-&#43;</span>
<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">|</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">|</span>
<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">&#43;</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">--</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">-&#43;</span>
<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span> row <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">in</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">set</span> (<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>0.01</strong></span> sec)
复制代码

如果停掉了mysql服务,则输出如下:

<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">root@localhost ~</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span><span style="margin:0px; padding:0px; line-height:1.5"># systemctl stop mysqld
</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">root@localhost ~</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span># echo <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">SELECT 1</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">|</span> &quot;${mysql<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">@</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span><span style="margin:0px; padding:0px; line-height:1.5">}&quot; 
ERROR </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>2002</strong></span> (HY000): Can<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">t connect to local MySQL server through socket </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">/</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,255)">var</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">/</span>lib<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">/</span>mysql<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">/</span>mysql.sock<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)"> (2)</span>

在这里,还有一点很让人疑惑,

 <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">if</span> echo <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">SELECT 1</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">|</span> &quot;${mysql<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">@</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span>}&quot; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">&amp;&gt;</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">/</span>dev<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">/</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">null</span>; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">then</span>
    <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">break</span><span style="margin:0px; padding:0px; line-height:1.5">
 fi</span>

if判断的条件难道不是echo ‘SELECT 1’ | "${mysql[@]}"命令的返回码么?如果是这样的话,成功执行,则$?为0,此时不应该执行break语句的,但事实与推测的相反。关于这点暂且留下。

9> 

mysql_tzinfo_to_sql <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">/</span>usr<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">/</span>share<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">/</span>zoneinfo <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">|</span> sed <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">s/Local time zone must be set--see zic manual page/FCTY/</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">|</span> &quot;${mysql<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">@</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span>}&quot; mysql

修改mysql关于时区的一个bug,不去深究。

10> 

复制代码
       &quot;${mysql<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">@</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span>}&quot; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">&lt;&lt;-</span><span style="margin:0px; padding:0px; line-height:1.5">EOSQL
            </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">--</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)"> What's done in this file shouldn't be replicated</span>
            <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">--</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">  or products like mysql-fabric won't work</span>
            <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">SET</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,0)"><strong>@@SESSION</strong></span>.SQL_LOG_BIN<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">=</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>0</strong></span><span style="margin:0px; padding:0px; line-height:1.5">;
            </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">DELETE</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">FROM</span> mysql.<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,255)">user</span><span style="margin:0px; padding:0px; line-height:1.5"> ;
            </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">CREATE</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,255)">USER</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">root</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span>@<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">%</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span> IDENTIFIED <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">BY</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">${MYSQL_ROOT_PASSWORD}</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5"> ;
            </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">GRANT</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">ALL</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">ON</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">*</span>.<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">*</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">TO</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">root</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span>@<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">%</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">WITH</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">GRANT</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">OPTION</span><span style="margin:0px; padding:0px; line-height:1.5"> ;
            </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">DROP</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">DATABASE</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">IF</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">EXISTS</span><span style="margin:0px; padding:0px; line-height:1.5"> test ;
            FLUSH </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">PRIVILEGES</span><span style="margin:0px; padding:0px; line-height:1.5"> ;
        EOSQL</span>
复制代码

这段主要是用客户端登录数据库进行相关操作,包括修改root密码,为其授权,删除测试数据库等。SET @@SESSION.SQL_LOG_BIN=0的作用是停止使用日志文件,这点不是很明白。

11> 

复制代码
        <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">if</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)"> ! -z &quot;$MYSQL_ROOT_PASSWORD&quot; </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span>; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">then</span><span style="margin:0px; padding:0px; line-height:1.5">
            mysql</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">&#43;=</span>( <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span><span style="margin:0px; padding:0px; line-height:1.5">p&quot;${MYSQL_ROOT_PASSWORD}&quot; )
        fi

        </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">if</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)"> &quot;$MYSQL_DATABASE&quot; </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span>; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">then</span><span style="margin:0px; padding:0px; line-height:1.5">
            echo &quot;</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">CREATE</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">DATABASE</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">IF</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">NOT</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">EXISTS</span> /`$MYSQL_DATABASE/` ;&quot; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">|</span> &quot;${mysql<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">@</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span><span style="margin:0px; padding:0px; line-height:1.5">}&quot;
            mysql</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">&#43;=</span><span style="margin:0px; padding:0px; line-height:1.5">( &quot;$MYSQL_DATABASE&quot; )
        fi

        </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">if</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)"> &quot;$MYSQL_USER&quot; -a &quot;$MYSQL_PASSWORD&quot; </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span>; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">then</span><span style="margin:0px; padding:0px; line-height:1.5">
            echo &quot;</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">CREATE</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,255)">USER</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">&quot;$MYSQL_USER&quot;</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span>@<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">%</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span> IDENTIFIED <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">BY</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">&quot;$MYSQL_PASSWORD&quot;</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span> ;&quot; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">|</span> &quot;${mysql<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">@</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span><span style="margin:0px; padding:0px; line-height:1.5">}&quot;

            </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">if</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)"> &quot;$MYSQL_DATABASE&quot; </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span>; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">then</span><span style="margin:0px; padding:0px; line-height:1.5">
                echo &quot;</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">GRANT</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">ALL</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">ON</span> /`&quot;$MYSQL_DATABASE&quot;/`.<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">*</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">TO</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">&quot;$MYSQL_USER&quot;</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span>@<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">%</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span> ;&quot; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">|</span> &quot;${mysql<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">@</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span><span style="margin:0px; padding:0px; line-height:1.5">}&quot;
            fi

            echo </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">FLUSH PRIVILEGES ;</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">|</span> &quot;${mysql<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">@</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span><span style="margin:0px; padding:0px; line-height:1.5">}&quot;
        fi</span>
复制代码

这段代码主要是创建数据库,新建mysql用户,并授权。这其实意味着用户在启动容器时可以通过指定MYSQL_DATABASE参数来创建数据库,通过MYSQL_USER和MYSQL_PASSWORD来创建新的数据库用户。

其中,mysql+=( -p"${MYSQL_ROOT_PASSWORD}" )用于拼接变量。譬如:

<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">root@localhost ~</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span># mysql<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">=</span>( mysql <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">--</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">protocol=socket -uroot )</span>
<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">root@localhost ~</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span># MYSQL_DATABASE<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">=</span><span style="margin:0px; padding:0px; line-height:1.5">docker
</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">root@localhost ~</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span># mysql<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">&#43;=</span><span style="margin:0px; padding:0px; line-height:1.5">( &quot;$MYSQL_DATABASE&quot; )
</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">root@localhost ~</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span># echo ${mysql<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">[</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">@</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">]</span><span style="margin:0px; padding:0px; line-height:1.5">}
mysql </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">--</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">protocol=socket -uroot docker</span>

12>

复制代码
<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">       for</span> f <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">in</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">/</span>docker<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span>entrypoint<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span>initdb.d<span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">/*</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,128,128)">; do
            case &quot;$f&quot; in
                *.sh)  echo &quot;$0: running $f&quot;; . &quot;$f&quot; ;;
                *.sql) echo &quot;$0: running $f&quot;; &quot;${mysql[@]}&quot; &lt; &quot;$f&quot; &amp;&amp; echo ;;
                *)     echo &quot;$0: ignoring $f&quot; ;;
            esac
            echo
        done      </span>
复制代码

其它需要执行的shell脚本或者sql脚本,可放到/docker-entrypoint-initdb.d/目录下。只需启动容器时,通过-v参数将容器该目录挂载到宿主机目录上。

13> 

        <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">if</span> ! <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">kill</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">-</span>s TERM &quot;$pid&quot; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">||</span> ! wait &quot;$pid&quot;; <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">then</span><span style="margin:0px; padding:0px; line-height:1.5">
            echo </span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,128,128)">&gt;&amp;</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>2</strong></span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">MySQL init process failed.</span><span style="margin:0px; padding:0px; line-height:1.5; color:rgb(255,0,0)">'</span>
            <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(0,0,255)">exit</span> <span style="margin:0px; padding:0px; line-height:1.5; color:rgb(128,0,0)"><strong>1</strong></span><span style="margin:0px; padding:0px; line-height:1.5">
        fi</span>

关闭已启动的mysql server,可能很多人会感到好奇,不是提供mysql服务么?为什么还要关闭呢?

答案就在于dockerfile中CMD的命令为 ["mysqld"],如果不关闭的话,这里就无法启动。

这里比较有意思的还是在于脚本部分,

一、关于kill,kill命令是通过向进程发送指定的信号来结束进程的。

-s的意思是Specify the signal to send.  The signal may be given as a signal name or number.指定需要发送的信号.

如果没有指定发送信号,那么默认值为TERM信号。

关于-TERM和-9的区别

kill -TERM PID:TERM是请求彻底终止某项执行操作.它期望接收进程清除自给的状态并退出,它是一种较温和的方式。

kill -9 PID:

这个强大和危险的命令迫使进程在运行时突然终止,进程在结束后不能自我清理。危害是导致系统资源无法正常释放,一般不推荐使用,除非其他办法都无效。

当使用此命令时,一定要通过ps -ef确认没有剩下任何僵尸进程。只能通过终止父进程来消除僵尸进程。如果僵尸进程被init收养,问题就比较严重了。杀死init进程意味着关闭系统。

如果系统中有僵尸进程,并且其父进程是init,而且僵尸进程占用了大量的系统资源,那么就需要在某个时候重启机器以清除进程表

二、关于||运算符

关于&&和||的区别

command1 && command2 :左边的命令(命令1)返回真(即返回0,成功被执行)后,&&右边的命令(命令2)才能够被执行。

command1 || command2:左边的命令(命令1)执行失败了,就执行右边的命令(命令2)。

三、关于wait

wait命令用来等待指令的完成,直到其执行完毕后返回终端。

所以这段脚本的逻辑是首先用kill -s TERM "$pid"的方式关闭mysqld进程,如果执行成功了,则! kill -s TERM "$pid"的结果为false,这时候就执行wait "$pid",wait是等待mysqld的关闭,mysqld关闭完毕后,wait "$pid"结果为真,此时! wait "$pid"结果为假。echo语句就不执行。

至此,分析完毕~

未经允许不得转载:冰点网络 » 分析mysql5.6镜像中的entrypoint.sh脚本

分享到:更多 ()

评论 抢沙发

评论前必须登录!