MYSQL中常用的工具

来源:互联网 发布:双色球免费过滤软件 编辑:程序博客网 时间:2024/04/30 05:02

 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客户端登陆后执行的一些功能非常类似!
可以执行的命令:

create databasename      Create a new database
   debug            Instruct server to write debug information to log
  drop databasename       Delete a database and all its tables
   extended-status   Gives an extended status message from the server
  flush-hosts         Flush all cached hosts
  flush-logs          Flush all logs
  flush-status        Clear status variables
  flush-tables        Flush all tables
  flush-threads       Flush the thread cache
  flush-privileges    Reload grant tables (same as reload)
   kill id,id,...      Kill mysql threads
   password new-password Change old password to new-password, MySQL 4.1 hashing.
   old-password new-password Change old password to new-password in old format.

   ping         Check if mysqld is alive
   processlist     Show list of active threads in server
   reload            Reload grant tables
  refresh        Flush all tables and close and open logfiles
  shutdown       Take server down
  status        Gives a short status message from the server
  start-slave          Start slave
  stop-slave         Stop slave
   variables          Prints variables available
  version          Get version info from server

eg: /usr/bin/mysqladmin -u root -p shutdown
/usr/bin/mysqladmin -u root -p password new-password(该用户原来有密码)
/usr/bin/mysqladmin -u root password new-password(该用户原来没有密码)

4.mysqlbinlog(日志管理工具)
my.cnf文件中能够看出来日志的存放路径
/usr/bin/mysqlbinlog 选项 日志文件名
-d:指定数据库名
-o:忽略掉日志中的n行
-r:将输出的文本格式日志输出到指定文件
-s:显示简单格式省略掉一些信息
--set-charset=char-name:在输出为文本格式时,在文件第一行加上set names char-name
--start-datetime=name --stop-datetime=name:指定日期间隔内的所有日志
--start-position=# --stop-position =#:指定位置间隔内的所有日志
eg:/usr/bin/mysqlbinlog ./bintest.000043
   出现error:/usr/bin/mysqlbinlog: unknown variable 'default-character-set=utf8'
改成:/usr/bin/mysqlbinlog --no-defaults ./bintest.000043
/usr/bin/mysqlbinlog --no-defaults ./bintest.000043 -d database-name
/usr/bin/mysqlbinlog --no-defaults ./bintest.000043 -o 3
/usr/bin/mysqlbinlog --no-defaults ./bintest.000043 -o 3 -r resultfile
/usr/bin/mysqlbinlog --no-defaults ./bintest.000043 -o 3 -s
/usr/bin/mysqlbinlog --no-defaults ./bintest.000043 --start-datetime='2007/08/30 05:00:00' --stop-datetime='2007/08/30 05:30:00'
usr/bin/mysqlbinlog --no-defaults ./bintest.000043 --start-position=4 --stop-position=196

5.mysqlcheck(MyISAM表维护工具)
mysqlcheck 选项 database-name[table-name]
mysqlcheck 选项 --database database-name1 [databases-name2]....
mysqlcheck 选项 --all-database
-c:检查表
-r:修复表
-a:分析表
-o:优化表
eg:mysqlcheck -u root -p -c datebase-name



7.mysqlshow(数据库对象查看工具)
mysqlshow -u root -p :显示所有数据库
mysqlshow -u root -p --count:显示数据库和表的统计信息
mysqlshow -u root -p db_name --count:指定数据库
mysqlshow -u root -p db_name table_name --count:指定数据库和表名
mysqlshow -u root -p db_name table_name -k:显示指定表中的索引
mysqlshow -u root -p db_name table_name -i:显示表的一些状态信息

8.perror(错误代码查看工具)
eg:查看错误号30是什么意思?
     perror 30

原创粉丝点击