mysql 初始執(zhí)行文件的使用介紹
可以在配置文件里指定mysql啟動(dòng)以后初始執(zhí)行的SQL文件, 其語(yǔ)法是:
在[mysqld]或者[server]下指定:
init-file=D:\mysql-5.5.28-winx64\abc.sql, 后邊為具體的sql文件值
注意下邊兩點(diǎn)就行了:
1. 確保你的mysqld 編譯的時(shí)候沒(méi)有加 --disable-grant-options 開關(guān)。
2. 確保init-file指定的腳本每行是一個(gè)具體的可以執(zhí)行的語(yǔ)句。
為了示例:
abc.sql為:
use test;
begin;
create table if not exists t123(id int);
insert into t123 values(1);
insert into t123 values(2);
select * from t123;
-- drop table t123;
end;
啟動(dòng)完mysql以后,得到查詢:
mysql> use test;
Database changed
mysql> select * from t123;
+------+
| id |
+------+
| 1 |
| 2 |
+------+
2 rows in set (0.00 sec)
第二次啟動(dòng)以后,得到結(jié)果:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.28 MySQL Community Server (GPL)
Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use test;
Database changed
mysql> select * from t123;
+------+
| id |
+------+
| 1 |
| 2 |
| 1 |
| 2 |
+------+
4 rows in set (0.00 sec)
相關(guān)文章
mysql通過(guò)@變量實(shí)現(xiàn)遞歸詳細(xì)實(shí)例
眾所周知目前的mysql版本中并不支持直接的遞歸查詢,下面這篇文章主要給大家介紹了關(guān)于mysql通過(guò)@變量實(shí)現(xiàn)遞歸的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-06-06mysql insert if not exists防止插入重復(fù)記錄的方法
在 MySQL 中,插入(insert)一條記錄很簡(jiǎn)單,但是一些特殊應(yīng)用,在插入記錄前,需要檢查這條記錄是否已經(jīng)存在,只有當(dāng)記錄不存在時(shí)才執(zhí)行插入操作,本文介紹的就是這個(gè)問(wèn)題的解決方案。2011-04-04MySQL: mysql is not running but lock exists 的解決方法
下面可以參考下面的方法步驟解決。最后查到一個(gè)網(wǎng)友說(shuō)可能和log文件有關(guān),于是將log文件給移除了,再重啟MySQL終于OK了2009-06-0630個(gè)mysql千萬(wàn)級(jí)大數(shù)據(jù)SQL查詢優(yōu)化技巧詳解
本文總結(jié)了30個(gè)mysql千萬(wàn)級(jí)大數(shù)據(jù)SQL查詢優(yōu)化技巧,特別適合大數(shù)據(jù)里的MYSQL使用2018-03-03MySQL實(shí)現(xiàn)批量更新不同表中的數(shù)據(jù)
這篇文章主要介紹了MySQL實(shí)現(xiàn)批量更新不同表中的數(shù)據(jù),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-05-05