mysql資料庫起動自動執行某個命令(init-file使用)

來源:互聯網
上載者:User

關於MySQL的init-file選項的用法執行個體

    init-file 是在MySQL啟動的時候載入的指令碼。

    有兩個要注意的。

    1. 確保你的mysqld 編譯的時候沒有加 --disable-grant-options 開關。

    2. 確保init-file指定的指令碼每行一個具體的語句。

    使用方法如下,直接添加到設定檔,比如my.cnf.

    添加:

    [server] 或者 [mysqld] 或者 [mysqld_safe]

    init-file="Your file location"

    # The following options will be passed to all MySQL clients

    [server]

    init-file=/usr/local/mysql567/init.file

    [root@ambow-school-system-hylm bin]# ll /usr/local/mysql567/init.file

    -rw-rw---- 1 mysql mysql 92 Dec 15:43 /usr/local/mysql567/init.file

    [root@hylm bin]cat /usr/local/mysql567/init.file

    use test;

    insert chen select substr(passid,1,7) a, max(passid) as aa from user group by a;

    [root@hylm bin]#

    mysql> show create table chen\G;

    *************************** 1. row ***************************

     Table: chen

    Create Table: CREATE TABLE `chen` (

     `pkey` char(8) default NULL,

     `value` char(25) default NULL

    ) ENGINE=MEMORY DEFAULT CHARSET=utf8

    1 row in set (0.00 sec)

    ERROR:

    No query specified

    mysql> show create table USER\G;

    *************************** 1. row ***************************

     Table: USER

    Create Table: CREATE TABLE `user` (

     `passid` char(25) default NULL

    ) ENGINE=MyISAM DEFAULT CHARSET=utf8

    1 row in set (0.00 sec)

    ERROR:

    No query specified

    mysql> select * from user;

    +-----------------+

    | passid |

    +-----------------+

    | apt1212100000 |

    | apt1212100002 |

    | apt1212100003 |

    | cisco1212100001 |

    | cisco1212100002 |

    | cisco1212100003 |

    | tmp1212100001 |

    | tmp1212100002 |

    | tmp1212100003 |

    +-----------------+

    9 rows in set (0.00 sec)

    mysql>

    重起後就可以看到如下:

    mysql> select * from chen;

    +---------+-----------------+

    | pkey | value |

    +---------+-----------------+

    | apt1212 | apt1212100003 |

    | cisco12 | cisco1212100003 |

    | tmp1212 | tmp1212100003 |

    +---------+-----------------+

    

    

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.