查看MySQL已经运行的时长

<pre class="brush:bash;toolbar:false">mysql&gt;showglobalstatuslike&#39;uptime&#39;; +---------------+--------+ |Variable_name|Value| +---------------+--------+ |Uptime|508718| +---------------+--------+ 1rowinset(0.00sec) uptime的单位为妙。 mysql&gt;\s -------------- mysqlVer14.14Distrib5.7.15,forlinux-glibc2.5(x86_64)usingEditLinewrapper Connectionid:110946 Currentdatabase: Currentuser:root@localhost SSL:Notinuse Currentpager:stdout Usingoutfile:&#39;&#39; Usingdelimiter:; Serverversion:5.7.15-logMySQLCommunityServer(GPL) Protocolversion:10 Connection:LocalhostviaUNIXsocket Servercharacterset:utf8mb4 Dbcharacterset:utf8mb4 Clientcharacterset:utf8mb4 Conn.characterset:utf8mb4 UNIXsocket:/tmp/mysql_trading.sock Uptime:5days21hours18min39sec Threads:919Questions:110671873Slowqueries:9309Opens:139712983Flushtables:1Opentables:0Queriespersecondavg:217.550</pre><p>uptime这个显示的为运行的天数 时分秒,换算为运行时间s则需要计算下。</p><p>通过查询进程查看进程运行的开始时间,不过这个查询方法不准确:</p><pre class="brush:bash;toolbar:false">[root@node1~]#ps-ef|grep-imysql mysql1488110Mar26?02:12:22/usr/local/mysql/bin/mysqld--user=mysql--datadir=/data/mysql/common--port=3306 --pid-file=/tmp/mysql_common.pid--socket=/tmp/mysql_common.sock--server-id=1--default-storage-engine=InnoDB--character-set-client-handshake=FALSE --character-set-server=utf8mb4--collation-server=utf8mb4_unicode_ci--init_connect=SETNAMESutf8mb4--performance-schema-instrument=memory/%COUNTED --interactive_timeout=172800--wait_timeout=172800--tmp-table-size=8M--max-heap-table-size=4M--query-cache-type=0 --query-cache-size=64M--max-connections=8000--thread-cache-size=50--open-files-limit=65535--table-definition-cache=4096 --table-open-cache=10--innodb-flush-method=O_DIRECT--innodb-log-files-in-group=2--innodb-log-file-size=256M --innodb-flush-log-at-trx-commit=1--innodb-file-per-table=1--innodb-buffer-pool-size=2G --log-error=/data/mysql/common/common_error.log--slow-query-log=1 --slow-query-log-file=/data/mysql/common/common_slow.log--long_query_time=0.2 --min_examined_row_limit=100--max-allowed-packet=16M--max-connect-errors=1000000 --skip-name-resolve--sql-mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO, NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION--sysdate-is-now=1--innodb-strict-mode=1--sort_buffer_size=2M--join_buffer_size=2M --key_buffer_size=64M--read_buffer_size=512K--read_rnd_buffer_size=256K--binlog_cache_size=2M--thread_stack=256K --bulk_insert_buffer_size=64M--lower_case_table_names=1--relay-log=/data/mysql/common/common_relay.log --relay_log_recovery=1--slave-net-timeout=60--relay_log_purge=0--sync_binlog=1- -log-bin=/data/mysql/common/common_bin.log--binlog_format=ROW--expire-logs-days=3 --relay_log_recovery=1--slave_skip_errors=ddl_exist_errors--explicit_defaults_for_timestamp=true--log_slave_updates=on</pre><p>上述中的Mar26即为mysql实例启动的时间!</p><p>通过查询MySQL的状态也可以大致查询出运行的时间:</p><pre class="brush:bash;toolbar:false">#systemctlstatusmysqld ●mysqld.service-MySQLServer Loaded:loaded(/usr/lib/systemd/system/mysqld.service;enabled;vendorpreset:disabled) Active:active(running)sinceFri2018-06-1511:32:35CST;2h15minago Docs:man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process:12713ExecStartPre=/usr/bin/mysqld_pre_systemd(code=exited,status=0/SUCCESS) MainPID:12737(mysqld) Status:&quot;SERVER_OPERATING&quot; CGroup:/system.slice/mysqld.service └─12737/usr/sbin/mysqld Jun1511:29:51node2systemd[1]:StartingMySQLServer... Jun1511:32:35node2systemd[1]:StartedMySQLServer.</pre>
返回顶部 留言