天天看點

MYSQL中常用的工具

1.mysql(用戶端連結工具):

   -u :指定使用者名

   -p:指定密碼

   -h:指定伺服器ip或者域名

   -P(大寫):指定端口

  例子:mysql -u root -h 202.194.132.237 -P 3306 -p

     出現error: Host '202.194.132.237' is not allowed to connect to this MySQL server

  出現上述原因是因為:該使用者沒有權利進行遠端通路,必須登陸資料庫修改使用者的權限.

  設定使用者管理權限:

  grant 權限清單 [(字段清單)] on 資料庫名.表名 to 使用者名@域名或ip位址 [identified by '密碼']   [with grant option]

  eg:

     1. grant all on *.* to wuxiaoxiao@'%' identified by '870805'

     2. grant select on java.* to wuxiaoxiao@'202.194.132.%' identified by '870805';

        grant update (name) on java.customer to wuxiaoxiao@'%';

     3. grant all on *.* to wuxiaoxiao@'localhost' identified by '870805';

  revoke 權限清單[(字段清單)] on 資料庫.表名 from 使用者名@域名或ip位址

     eg:revoke create,drop on java.* from wuxiaoxiao@'%';

        revoke grant option on java.* from wuxiaoxiao@localhost;

 登陸系統後:select current_user();檢視目前連結的使用者

  --default-character-set=gbk:設定用戶端字元集選項

 eg:mysql -u root --defaule-character-set=gbk -p登陸後:

    等價與set names gbk;

    show  variables like  'chara%';檢視用戶端字元集

-e:執行sql語句并退出:

  msyql -u root -e "select * from user" 資料褲名字 -p

-E:将輸出方式按照字段順序豎着顯示

-s:去掉mysql中的線條框顯示

eg:mysql -u root -e "select * from user" BBS -p -E

-f:強行執行sql語句

-v:顯示更多資訊

--show-warnings:顯示警告資訊

eg:

在資料庫test中有個表t2,隻有一個字段id,是int型的

有以下幾條插入語句(a.sql):

insert into t2 values(1);

insert into t2 values(2a);//錯誤

insert into t2 values(3);

不加上任何參數:

mysql -u root test(database-name) < a.sql

會出現錯誤,一條sql都沒有執行

加上參數-f:

mysql -u root test(database-name) -f< a.sql

隻有錯誤的那行沒有執行

加上-v顯示插入的詳細資訊:

mysql -u root test(database-name) -f -v< a.sql

加上--show-warnings

mysql -u root test(database-name) -f -v --show-warnings< a.sql

2.myisampack(MyISAM表壓縮工具)

  eg:myisampack t3(t3.myd)

3.mysqladmin(MySQL管理工具)

  mysqladmin和mysql用戶端登陸後執行的一些功能非常類似!

  可以執行的指令: