關於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 |
+---------+-----------------+