iis服务器助手广告广告
返回顶部
首页 > 资讯 > 数据库 >MySQL mysqladmin客户端的使用简介
  • 761
分享到

MySQL mysqladmin客户端的使用简介

MySQLmysqladmin客户端MySQLmysqladmin客户端使用 2022-05-25 14:05:12 761人浏览 泡泡鱼
摘要

     Mysqladmin是mysql官方提供的shell命令行工具,它的参数都需要在shell命令行里面执行,当我们使用mysqladmin的时候,必须指定两类参数,一类

     Mysqladmin是mysql官方提供的shell命令行工具,它的参数都需要在shell命令行里面执行,当我们使用mysqladmin的时候,必须指定两类参数,一类是连接参数,另外一类是命令参数,连接参数用来指定相应的连接信息,而命令参数用来指定命令信息,例如可以用来检查服务器的配置和当前状态、创建和删除数据库等。它的语法如下:


mysqladmin [options] command [command-options] [command [command options]] ...

除此之外,还有一些相关的参数配置(代码可以左滑哦~):


--bind-address=name 绑定远程访问主机的ip地址
-i, --sleep=#   间隔多长时间执行一次。
-c, --count=#   统计计数。与i选项配合使用。
-f, --force   强制执行,删除数据库是无需确认信息,多条语句执行时忽略其中某条语句的错误。
--default-character-set=name 设置默认字符集。
-?, --help    显示帮助信息。
-h, --host=name  指定连接主机。
-u, --user=name  登录用户。
-p, --passWord[=name] 登录密码,如果不写于参数后,则会提示输入。
-P, --port=#   指定数据库端口。
--protocol=name  使用的连接协议。(tcpSocket,pipe,memory)
-r, --relative   显示前后两次输出的差异。必须与i选项配合使用。
-s, --silent   静默退出。
-S, --socket=name  指定socket文件。
-v, --verbose   显示更多信息。
-V, --version   显示版本信息。
-w, --wait[=#]   如果连接断开,等待指定的时间后重试

    这么多参数,想看着比较乱,那么我们来看看它具体能够帮我们做哪些事情吧:

1.查看服务器的状态:


#每隔两秒查看一次服务器的状态
[root@dev01 ~]# mysqladmin -uroot -p -i 2 -c 2 status
Enter password: 
Uptime: 42767 Threads: 2 Questions: 533 Slow queries: 0 Opens: 346 Flush tables: Open tables: Queries per second avg: 0.012
Uptime: Threads: Questions: Slow queries: Opens: Flush tables: Open tables: Queries per second avg: 0.012

2.修改root密码:


#修改root密码
mysqladmin -u root -p原密码 password 'newpassword'

3.检查mysqlserver是否可用


#查询服务是否正常
[root@dev01 ~]# mysqladmin -uroot -p ping
Enter password: 
mysqld is alive

4.查询服务器的版本


[root@dev01 ~]# mysqladmin -uroot -p version
Enter password: 
mysqladmin Ver 8.42 Distrib 5.7.19, for linux-glibc2.12 on x86_64
Copyright (c) 2000, 2017, 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.

Server version  5.7.19
Protocol version 10
Connection  Localhost via UNIX socket
UNIX socket  /tmp/mysql.sock
Uptime:   12 hours 42 sec

Threads: 2 Questions: 538 Slow queries: 0 Opens: 346 Flush tables: 1 Open tables: 285 Queries per second avg: 0.012

5.查看系统当前的状态值 (省略其中的部分结果)


[root@dev01 ~]# mysqladmin -uroot -p extended-status
Enter password: 
+-----------------------------------------------+----------+
| Variable_name         | Value |
+-----------------------------------------------+----------+
| Aborted_clients        |   |
| Aborted_connects        |   |
| Innodb_num_open_files       |  |
| Innodb_truncated_status_writes    |   |            
| Uptime          |  |
| Uptime_since_flush_status      |  |
+-----------------------------------------------+----------+

6.查看服务器系统变量值


[root@dev01 ~]# mysqladmin -uroot -p variables
Enter password: 
......
| key_cache_block_size    |                                                                                         |
| key_cache_division_limit   |                                                                                             |
| large_files_support    | ON                                                                                                    |
| large_page_size     |                                                                                                     |
| large_pages      | OFF                                                                                                    |
| lc_messages      | en_US                                                                                                   |
| lc_messages_dir     | /usr/local/mysql/share/                                                                                               |
......

7.查看当前所有的进程


[root@dev01 ~]# mysqladmin -uroot -p processlist
Enter password: 
+----+------+----------------------+----------+---------+-------+----------+------------------+
| Id | User | Host     | db  | Command | Time | State | Info    |
+----+------+----------------------+----------+---------+-------+----------+------------------+
| | root | 192.168.56.102: | devopsdb | Sleep | |   |     |
| | root | localhost   |   | Query |  | starting | show processlist |
+----+------+----------------------+----------+---------+-------+----------+------------------+

8.创建数据库


[root@dev01 ~]# mysqladmin -uroot -p create db_test
Enter password: 
[root@dev01 ~]# mysql -uroot -p
Enter password: 
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 
Server version: 5.7.19 MySQL CommUnity Server (GPL)

Copyright (c) 2000, 2017, 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> show databases;
+--------------------+
| Database   |
+--------------------+
| infORMation_schema |
| TkGrowDB_dbo  |
| TkGrowLog_dbo  |
| cydevopsdb   |
| db_test   |
| yeyz    |
+--------------------+
 rows in set (0.00 sec)

mysql> exit
Bye

从上面的命令我们可以看到,我们已经通过create命令创建了数据库db_test

9.删除特定的数据库:


[root@dev01 ~]# mysqladmin -uroot -p drop db_test
Enter password: 
Dropping the database is potentially a very bad thing to do.
Any data stored in the database will be destroyed.

Do you really want to drop the 'db_test' database [y/N] y
Database "db_test" dropped
[root@dev01 ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 
Server version: 5.7.19 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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> show databases;
+--------------------+
| Database   |
+--------------------+
| information_schema |
| TkGrowDB_dbo  |
| TkGrowLog_dbo  |
| cydevopsdb   |
| yeyz    |
+--------------------+
 rows in set (0.00 sec)

    在我们日常操作中,drop操作应该谨慎一些,可以看到,mysql也友好的给出了提醒。

10.重载权限表和刷新缓存(无明显输出)


[root@dev01 ~]# mysqladmin -uroot -p reload
Enter password:
[root@dev01 ~]# mysqladmin -uroot -p refresh
Enter password:

11.启用安全模式关闭数据库


[root@dev01 ~]# ps -ef|grep mysqld
root    : ?  :: /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/dev01.pid
mysql   : ?  :: /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/mysqld.log --pid-file=/data/mysql/dev01.pid --socket=/tmp/mysql.sock
root   : pts/ :: grep mysqld
[root@dev01 ~]# mysqladmin -uroot -p shutdown
Enter password: 
[root@dev01 ~]# ps -ef|grep mysqld
root   : pts/ :: grep mysqld

12.各种刷新命令


[root@dev01 ~]# mysqladmin -u root -ptmppassword flush-hosts
[root@dev01 ~]# mysqladmin -u root -ptmppassword flush-logs
[root@dev01 ~]# mysqladmin -u root -ptmppassword flush-privileges
[root@dev01 ~]# mysqladmin -u root -ptmppassword flush-status
[root@dev01 ~]# mysqladmin -u root -ptmppassword flush-tables
[root@dev01 ~]# mysqladmin -u root -ptmppassword flush-threads

13.停止和启动MySQL从节点复制过程


[root@dev01 ~]# mysqladmin -u root -p stop-slave
[root@dev01 ~]# mysqladmin -u root -p start-slave

以上就是mysqladmin最常用的一些功能,标注为红色的一般在工作中应用的范围及其广泛,可以多留意下。

以上就是MySQL mysqladmin客户端的使用简介的详细内容,更多关于MySQL mysqladmin客户端的资料请关注自学编程网其它相关文章!

您可能感兴趣的文档:

--结束END--

本文标题: MySQL mysqladmin客户端的使用简介

本文链接: https://www.lsjlt.com/news/10262.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • sql怎么查看表的索引
    通过查询系统表,可以获取表的索引信息,包括索引名称、是否唯一、索引类型、索引列和行数。常用系统表有:mysql 的 information_schema.statistics、postg...
    99+
    2024-05-14
    mysql oracle
  • sql怎么查看索引
    您可以使用 sql 通过以下方法查看索引:show indexes 语句:显示表中定义的索引列表及其信息。explain 语句:显示查询计划,其中包含用于执行查询的索引。informat...
    99+
    2024-05-14
  • sql怎么查看存储过程
    如何查看 sql 存储过程的源代码:使用 show create procedure 语句直接获取创建脚本。查询 information_schema.routines 表的 routi...
    99+
    2024-05-14
  • sql怎么查看视图表
    要查看视图表,可以使用以下步骤:使用 select 语句获取视图中的数据。使用 desc 语句查看视图的架构。使用 explain 语句分析视图的执行计划。使用 dbms 提供...
    99+
    2024-05-14
    oracle python
  • sql怎么查看创建的视图
    可以通过sql查询查看已创建的视图,具体步骤包括:连接到数据库并执行查询select * from information_schema.views;查询结果将显示视图的名称、...
    99+
    2024-05-14
    mysql
  • sql怎么用循环语句实现查询
    可以通过 do 和 while 语句创建循环,并在循环内执行查询,详细步骤包括:定义循环变量设置循环初始值循环执行查询更新循环变量执行查询循环退出条件 SQL 中使用循环语句实现查询 ...
    99+
    2024-05-14
  • sql怎么用代码修改表中数据
    通过 sql 代码修改表中数据的方法包括:修改单个记录:使用 update 语句设置列值并指定条件。修改多条记录:在 update 语句中指定多个条件来修改满足条件的所有记录。增加新列:...
    99+
    2024-05-14
  • sql怎么用命令创建数据库
    在 sql 中使用 create database 命令创建新数据库,其语法包含以下步骤:指定数据库名称。指定数据库文件和日志文件的位置(可选)。指定数据库大小、最大大小和文件增长(可选...
    99+
    2024-05-14
  • sql怎么用身份证提取年龄
    sql 中提取身份证号码中的年龄的方法:提取出生日期部分(身份证号码中第 7-14 位);使用 to_date 函数转换为日期格式;使用 extract 函数计算与当前日期之间的年差。 ...
    99+
    2024-05-14
  • sql怎么看字段长度
    有两种方法可查看 sql 中的字段长度:使用 information_schema 架构,其中包含元数据信息,可用于查询字段长度。使用内建函数,如 length(),其适用于字符串数据类...
    99+
    2024-05-14
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作