遠端存取
mysql -h localhost -uroot -p
修改密碼
mysqladmin -uroot -proot password admin
如果原密碼為空白
mysqladmin -uroot password admin
顯示版本號碼、狀態、進程資訊等
mysqladmin version status proc
啟動服務
net start mysql
關閉服務
mysqladmin -uroot -proot shutdown
查看版本和時間
select version(),current_date();
查看目前時間
SELECT NOW();
查看系統使用者
SELECT USER();
還可以算算術
select (25+6) as ad2d, (6*3) as xxx;
使用下面命令將文字檔“mydata.txt”裝載到test1表中:
load data local infile "c:/mydata.txt" into table test1;
如:
112hua
213daming
欄位之間用tab隔開(歡迎交流 http://www.111cn.net)
刪除表中 NULL的行
delete from test1 where age is NULL;
只刪除一行
delete from test1 where age='12' limit 1
修改列名(欄位名)
alter table testtb change name newname char;
備份資料庫
mysqldump -uroot -p test>aa.sql
還原資料庫
mysql -uroot -p test1<d:/aa.sql
建立一個使用者,讓他能在所有地方登陸,並能對所有的資料庫進行操作
grant select,insert,update,delete on *.* to darex@"%" identified by "root";
建立一個使用者,讓他只能在本機上登陸,只能訪問test資料庫
grant select,insert,update,delete on test.* to locdarex@localhost identified by "root";
修改定界符
delimiter ;
建立一個觸發器
create trigger tg1
after delete on test1
for each row
begin
delete from infos where id=old.id;
end;;
表的自我複製
insert into message (sender,getter,m_content,m_date) select sender,getter,m_content,m_date from message;
左串連查詢
select * from a left jion b on a.id=b.id;
1.匯出整個資料庫
mysqldump -u 使用者名稱 -p --default-character-set=latin1 資料庫名 > 匯出的檔案名稱(資料庫預設編碼是latin1)
mysqldump -u wcnc -p smgp_apps_wcnc > wcnc.sql
2.匯出一個表
mysqldump -u 使用者名稱 -p 資料庫名 表名> 匯出的檔案名稱
mysqldump -u wcnc -p smgp_apps_wcnc users> wcnc_users.sql
3.匯出一個資料庫結構
mysqldump -u wcnc -p -d –add-drop-table smgp_apps_wcnc >d:wcnc_db.sql
-d 沒有資料 –add-drop-table 在每個create語句之前增加一個drop table
4.匯入資料庫
A:常用source 命令
進入mysql資料庫控制台,
如mysql -u root -p
mysql>use 資料庫
然後使用source命令,後面參數為指令檔(如這裡用到的.sql)
mysql>source wcnc_db.sql
B:使用mysqldump命令
mysqldump -u username -p dbname < filename.sql
C:使用mysql命令
mysql -u username -p -D dbname < filename.sql
不是手冊,所以不能做到面面俱到,這些都是我平時總結的一些。