mysql 开发进阶篇系列 32 工具篇(mysqladmin工具)新浦
一.概述
mysqladmin是一个执行管理操作的客户端程序。用来检要服务的配置和当前的状态,创建并删除数据库等。功能与mysql客户端类似,主要区别在于它更侧重于一些管理方面的功能。
查找mysqladmin工具
--同样还是找到安装基地址bin目录下:
[root@hsr bin]# pwd /usr/local/mysql/bin
下面是可以执行的命令行以及描述
[root@hsr bin]# ./mysqladmin 语法如下:mysqladmin [option] command [command option] command ......
2 查看mysql 活动线程列表
[root@hsr bin]# ./mysqladmin -uroot -p processlist
or
[root@hsr bin]# ./mysqladmin -uroot -p proc
查看mysql 活动线程列表 每秒一次。 ctrl+c 停止
[root@hsr bin]# ./mysqladmin -uroot -p -i 1 processlist
- 查看服务器的状态, 每两秒查看一次状态,总共重复5次。
Uptime MySQL服务器已经运行的秒数
Threads
活跃线程(客户)的数量 包括sleep线程
Questions 从mysqld启动起来自客户问题的数量
Slow queries
已经超过long_query_time秒的查询数量
Opens mysqld已经打开了多少表
Flush tables flush ..., refresh和reload命令数量
Open tables 现在被打开的表数量
[root@hsr bin]# ./mysqladmin -uroot -p -i 2 -c 5 status
修改root密码
[root@hsr bin]# ./mysqladmin -uroot -p password 1234567
6.检查mysql服务是否可用
[root@hsr bin]# ./mysqladmin -uroot -p ping
7.检查当前服务版本
[root@hsr bin]# ./mysqladmin -uroot -p version
8.检查当前服务状态值
[root@hsr bin]# ./mysqladmin -uroot -p extended-status
- kill掉mysql线程ID
- 删除数据库 daba-test
mysqladmin -uroot -p drop daba-test
- 重载权限信息
mysqladmin -uroot -p reload
更多使用方法参看:mysqladmin文档
一般出来忘记密码都是一新mysql新手朋友,下面我们来告诉你如何利用mysqadmin来把密码修改过来吧。
我来做几个例子相信很快就明白了 。
1、原来的密码是123456
C:>type mysql5.bat
@echo off
mysql -uroot -p123456 -P3306
正确的修改MYSQL用户密码的格式是:
我们这里用
用户:root(可以换成其他的)
密码:woshiduide
来演示新密码。
代码如下
复制代码
C:>mysqladmin -uroot -p password woshiduide
Enter password: ******
于是修改成功。
注意PASSWORD关键字后面的空格
有好多人是这样修改的:
代码如下
复制代码
C:>mysqladmin -uroot -p password ‘woshiduide’
Enter password: ******
C:>mysqladmin -uroot -p password ‘woshiduide’
Enter password: *********
Warning: single quotes were not trimmed from the password by your
command
line client, as you might have expected.
而这个时候真正的密码是’woshiduide’
代码如下
复制代码
C:>mysql -uroot -p’woshiduide’
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 18
Server version: 5.1.17-beta-community-nt-debug MySQL Community Server
(GPL)
Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the buffer.
mysql>
而新手往往这样:
代码如下
复制代码
C:>mysql -uroot -pwoshiduide
ERROR 1045 (28000): Access denied for user ‘root’@'localhost’ (using
password: Y
ES)
所以非常郁闷,BAIDU、GOOGLE的搜了一大堆。
我现在把密码改回去。