• MySQL 常用命令(4)------mysqladmin命令详解


    mysqladmin是一个执行管理操作的客户端程序。它可以用来检查服务器的配置和当前状态、创建和删除数据库等。

    mysqladmin 工具的使用格式:

    mysqladmin [option] command [command option] command ......

    option 选项:

    -c number 自动运行次数统计,必须和 -i 一起使用
    -i number 间隔多长时间重复执行
    每个两秒查看一次服务器的状态,总共重复5次。
    ./mysqladmin -uroot -p -i 2 -c 5 status
    -h, --host=name Connect to host. 连接的主机名或iP
    -p, --password[=name] 登录密码,如果不写于参数后,则会提示输入
    -P, --port=# Port number to use for connection. 指定数据库端口
    -s, --silent Silently exit if one can't connect to server.
    -S, --socket=name Socket file to use for connection. 指定socket file
    -i, --sleep=# Execute commands again and again with a sleep between. 间隔一段时间执行一次
    -u, --user=name User for login if not current user.登录数据库用户名
    -v, --verbose Write more information. 写更多的信息
    -V, --version Output version information and exit. 显示版本

    mysqladmin的相关命令:
    mysqladmin password test123                  #<==设置密码,前文用过的。
    mysqladmin -uroot -ptest123 password dadong  #<==修改密码,前文用过的。
    mysqladmin -uroot -ptest123 status           #<==查看状态,相当于show status。
    mysqladmin -uroot -ptest123 -i 1 status      #<==每秒查看一次状态。
    mysqladmin -uroot -ptest123 extended-status   #<==等同show global status;。
    mysqladmin -uroot -ptest123 flush-logs        #<==切割日志。
    mysqladmin -uroot -ptest123 processlist       #<==查看执行的SQL语句信息。
    mysqladmin -uroot -ptest123 processlist -i 1  #<==每秒查看一次执行的SQL语句。
    mysqladmin -uroot -ptest123 shutdown           #<==关闭mysql服务,前文用过的。
    mysqladmin -uroot -ptest123 variables          #<==相当于show variables。

    实例
    1、查看服务器的状况:status

     [root@mysql ~]# mysqladmin -uroot -p status
     Enter password:
     Uptime: 1058 Threads: 3 Questions: 865389 Slow queries: 0 Opens: 282 Flush tables: 1

     Open  tables: 156 Queries per second avg: 817.948

    2.修改root 密码:
    mysqladmin -u root -poldpassword password 'newpassword'
    3.检查mysqlserver是否可用:
    mysqladmin -uroot -p ping
    显示结果:
    mysqld is alive

    4.查询服务器的版本
    mysqladmin -uroot -p version

    5.显示服务器所有运行的进程:
    mysqladmin -uroot -p processlist
    mysqladmin -uroot -p-i 1 processlist 每秒刷新一次
    [root@DB02 ~]# mysqladmin -uroot -p processlist
    Enter password:
    +----+------+-----------+----+---------+------+-------+------------------+
    | Id | User | Host      | db | Command | Time | State | Info             |
    +----+------+-----------+----+---------+------+-------+------------------+
    | 8  | root | localhost |    | Query   | 0    | init  | show processlist |
    +----+------+-----------+----+---------+------+-------+------------------+
    [root@DB02 ~]# mysqladmin -uroot -p -i 1 processlist
    Enter password:
    +----+------+-----------+----+---------+------+-------+------------------+
    | Id | User | Host      | db | Command | Time | State | Info             |
    +----+------+-----------+----+---------+------+-------+------------------+
    | 9  | root | localhost |    | Query   | 0    | init  | show processlist |

    6.创建数据库
    mysqladmin -uroot -p create daba-test
    [root@DB02 ~]# mysqladmin -uroot -pdadong123 create lili
    Warning: Using a password on the command line interface can be insecure.
    [root@DB02 ~]#
    mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | lili               |
    | mao                |
    | mysql              |
    | dadong             |
    | hehe            |
    | performance_schema |
    +--------------------+
    7 rows in set (0.00 sec)
    9.显示服务器上的所有数据库
    mysqlshow -uroot -p
    
    10.显示数据库daba-test下有些什么表:
    mysqlshow -uroot -p daba-test
    
    [root@DB02 ~]# mysqlshow -uroot -pdadong123 mysql
    Warning: Using a password on the command line interface can be insecure.
    Database: mysql
    +---------------------------+
    |          Tables           |
    +---------------------------+
    | columns_priv              |
    | db                        |
    | event                     |
    | func                      |
    
    11.统计daba-test 下数据库表列的汇总
    mysqlshow -uroot -p daba-test -v
    
    12.统计daba-test 下数据库表的列数和行数
    mysqlshow -uroot -p daba-test -v -v
    
    13. 删除数据库 daba-test
    mysqladmin -uroot -p drop daba-test
    
    14. 重载权限信息
    mysqladmin -uroot -p reload
    
    15.刷新所有表缓存,并关闭和打开log
    mysqladmin -uroot -p refresh
    
    16.使用安全模式关闭数据库
    mysqladmin -uroot -p shutdown

    17.mysqladmin flush commands

    # mysqladmin -u root -ptmppassword flush-hosts
    # mysqladmin -u root -ptmppassword flush-logs
    # mysqladmin -u root -ptmppassword flush-privileges
    # mysqladmin -u root -ptmppassword flush-status
    # mysqladmin -u root -ptmppassword flush-tables
    # mysqladmin -u root -ptmppassword flush-threads

    •flush-hosts: Flush all information in the host cache.
    •flush-privileges: Reload the grant tables (same as reload).
    •flush-status: Clear status variables.
    •flush-threads: Flush the thread cache.
    18 .mysqladmin 执行kill 进程:

    ./mysqladmin -uroot -p processlist

    ./mysqladmin -uroot -p kill idnum

    19.停止和启动MySQL replication on a slave server

    mysqladmin -u root -p stop-slave

    mysqladmin -u root -p start-slave

    20 .同时执行多个命令

    mysqladmin -u root -p process status version

     
     


  • 相关阅读:
    共享经济
    滑动用hammer
    js 数组去重 的5种方法
    js ajax上传图片到服务器
    js url图片转bese64
    去除移动端 a标签 点击有一个 阴影效果
    css 文字超出变 ... 点点点
    h5手势库 hammer.js
    xshell linux传文件
    IO流(Properties存取)
  • 原文地址:https://www.cnblogs.com/zhm1985/p/13093436.html
Copyright © 2020-2023  润新知