• 涂抹mysql笔记-mysql管理工具


    五花八门的mysql管理工具
    <>mysql提供的命令行工具
    mysql_install_db:mysql建库工具,在源码安装mysql环节我们使用过。
    mysql_safe:mysql启动工具
    mysqld:mysql主进程,mysql_safe也是调用mysqld进程。启动关闭数据库、查询或修改数据、执行各项维护操作等实际上都是基于mysqld进程的操作。
    系统参数:mysql服务启动时的参数
    系统变量:mysql服务运行时参数。比如查看与log相关的系统变量使用show global variables like 'log%';系统变量有些可以动态调整而不需要重启mysql,有些则不行。
    比如修改mysql数据库认到二进制日志格式为row格式。那么直接修改系统变量set global binlog_format=row;
    使用show global variables like 'binlog_format';查看系统变量是否修改。系统变量又分为全局(global)和会话(session)。无论全局还是会话级在下次mysql服务重启后设定就失效,只有在初始化文件中添加才能永久生效。
    状态变量:状态变量记录mysql服务的系统状态。状态变量也分为全局和会话,前者记录的是整个mysql服务的状态,而后者只代表当前会话的状态。查看mysql的状态变量:show global status;
    系统参数和系统变量之间并不是完全一比一关系,完全存在有参数但没变量,或者有变量却不存在对应参数的情况。

    <>mysqld_multi:mysql多实例管理工具需要在my.cnf添加不同的mysqld区块。使用mysqld_multi --example可以参考。这个命令专用于单个服务器上运行多个mysql实例的场景
    启动[mysqld34]这个区块:mysqld_multi start 34;
    停止[mysqld6] [mysqld7] [mysqld8]三个区块:mysqld_multi stop 6-8;

    <>mysql命令
    --auto-rehash:按Tab键补全命令
    --default-character-set:用于指定连接会话的字符集
    -e,--execute:mysql命令支持两种操作方式,交互式和非交互式。交互式就是引入到mysql命令提示符下执行的操作,非交互式执行mysql命令时,直接指定要执行的语句。比如:
    [mysql@linux02 scripts]$ mysql -usystem -poralinux -S /mysql/conf/mysql.sock -e "show slave statusG"
    Warning: Using a password on the command line interface can be insecure.
    *************************** 1. row ***************************
    Slave_IO_State: Waiting for master to send event
    Master_Host: 192.168.1.6
    Master_User: repl
    Master_Port: 3306
    Connect_Retry: 60
    Master_Log_File: mysql-bin.000024
    ...
    ...
    Master_Bind:
    Last_IO_Error_Timestamp:
    Last_SQL_Error_Timestamp:
    Master_SSL_Crl:
    Master_SSL_Crlpath:
    Retrieved_Gtid_Set:
    Executed_Gtid_Set:
    Auto_Position: 0

    -f,--force:在非交互模式批量执行sql语句(或执行一个包含sql语句的文件)时如果要执行的某条sql语句有错误,那么默认情况下改条语句后面所有语句都不会再被执行。例如:
    [mysql@linux02 scripts]$ mysql -usystem -poralinux -S /mysql/conf/mysql.sock -e "drop table aa.bbccdd;show slave statusG"
    Warning: Using a password on the command line interface can be insecure.
    ERROR 1051 (42S02) at line 1: Unknown table 'aa.bbccdd'
    上来就报有未知的表对象,后面那个查看slave状态的语句就不执行了。有时候我们希望错误的信息被自动忽略继续执行后面的语句,这时候-f参数就派上用场了。
    [mysql@linux02 scripts]$ mysql -usystem -poralinux -S /mysql/conf/mysql.sock -e "drop table aa.bbccdd;show slave statusG" -f
    Warning: Using a password on the command line interface can be insecure.
    ERROR 1051 (42S02) at line 1: Unknown table 'aa.bbccdd'
    *************************** 1. row ***************************
    Slave_IO_State: Waiting for master to send event
    Master_Host: 192.168.1.6
    Master_User: repl
    Master_Port: 3306
    Connect_Retry: 60
    Master_Log_File: mysql-bin.000024
    Read_Master_Log_Pos: 120
    Relay_Log_File: mysql-relay-bin.000011
    ...
    ...
    Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
    Master_Retry_Count: 86400
    Master_Bind:
    Last_IO_Error_Timestamp:
    Last_SQL_Error_Timestamp:
    Master_SSL_Crl:
    Master_SSL_Crlpath:
    Retrieved_Gtid_Set:
    Executed_Gtid_Set:
    Auto_Position: 0

    --show-warings:执行完语句后马上显示警告信息,相当于执行完sql语句后要自动执行show warings;语句

    system@(none)>help

    For information about MySQL products and services, visit:
    http://www.mysql.com/
    For developer information, including the MySQL Reference Manual, visit:
    http://dev.mysql.com/
    To buy MySQL Enterprise support, training, or other products, visit:
    https://shop.mysql.com/

    List of all MySQL commands:
    Note that all text commands must be first on line and end with ';'
    ? (?) Synonym for `help'.
    clear (c) Clear the current input statement.
    connect ( ) Reconnect to the server. Optional arguments are db and host.
    delimiter (d) Set statement delimiter.
    edit (e) Edit command with $EDITOR.
    ego (G) Send command to mysql server, display result vertically.
    exit (q) Exit mysql. Same as quit.
    go (g) Send command to mysql server.
    help (h) Display this help.
    nopager ( ) Disable pager, print to stdout.
    notee ( ) Don't write into outfile.
    pager (P) Set PAGER [to_pager]. Print the query results via PAGER.
    print (p) Print current command.
    prompt (R) Change your mysql prompt.
    quit (q) Quit mysql.
    rehash (#) Rebuild completion hash.
    source (.) Execute an SQL script file. Takes a file name as an argument.
    status (s) Get status information from the server.
    system (!) Execute a system shell command.
    tee (T) Set outfile [to_outfile]. Append everything into given outfile.
    use (u) Use another database. Takes database name as argument.
    charset (C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
    warnings (W) Show warnings after every statement.
    nowarning (w) Don't show warnings after every statement.

    For server side help, type 'help contents'

    pager是mysql命令行模式中的管道符。
    pager more可以分屏显示。pager后面跟的是操作系统命令,可以根据需求换成任何其他命令。nopager取消

    prompt修改当前命令行提示符
    status特别关注最后两行
    tee类似oracle中的spool

    <>mysqladmin管理工具
    常用参数:
    -i,--sleep=#:建个指定时间后,再次重复调用本mysqladmin命令
    -r,--relative:当与-i参数联合使用并且指定了extended-status命令时,显示本次与上次之间各状态值之间的差异。
    常用命令:
    1、create dbname:mysqladmin -usystem -p'oralinux' -S /mysql/conf/mysql.sock create testdb
    2、drop dbname:mysqladmin -usystem -p'oralinux' -S /mysql/conf/mysql.sock drop testdb
    3、extended-status:查看服务端状态信息,跟在mysql命令行模式下执行show global status的功能一样:
    mysqladmin -usystem -p'oralinux' -S /mysql/conf/mysql.sock extended-status
    4、flush-hosts:刷新缓存信息
    5、flush-logs:刷新日志
    6、flush-status:重置状态变量
    7、flush-tables:刷新所有表
    8、flush-privilege:重新加载授权表,功能与reload命令完全相同
    9、reload
    10、refresh:刷新所有表并切换日志文件
    11、password [new-password]:修改指定用户的密码,功能与set password语句完全相同。
    12、old-password [new-password]:修改指定用户密码,只是按照旧的格式修改
    12、ping:检查当前mysql服务是的仍能正常提供服务。
    mysqladmin -usystem -p'oralinux' -S /mysql/conf/mysql.sock ping
    13、debug:输出当前mysql服务的调试信息到error.log文件中,某些情况下性能分析或故障排查非常实用。
    14、kill id、id、...:杀掉连接至mysql服务的线程,功能与kill id语句完全相同
    15、processlist:查看当前mysql服务所用的连接线程信息,功能完全等同于show processlist;语句
    16、shutdown:关闭数据库服务
    17、status:查看当前mysql的状态
    [mysql@linux02 ~]$ mysqladmin -usystem -p'oralinux' -S /mysql/conf/mysql.sock status
    Warning: Using a password on the command line interface can be insecure.
    mysqladmin: Unknown OS character set 'GB18030'.
    mysqladmin: Switching to the default character set 'utf8'.
    Uptime: 3684 Threads: 3 Questions: 60 Slow queries: 0 Opens: 82 Flush tables: 1 Open tables: 75 Queries per second avg: 0.016
    下面几个可以作为监控指标:
    Uptime:mysql服务启动时间
    Thread:当前连接的会话数
    Questions:自mysql服务启动后执行查询语句数量
    Slow queries:慢查询语句数量
    Opens:当前处于打开状态的表对象的数量
    Flush tables:执行过flush-*、refresh、reload命令的数量
    Open tables:当前会话打开的表对象的数量
    Queries per second avg:查询的执行频率
    start-salve
    stop-slave
    variables:显示系统变量功能与show global variables;语句完全相同
    version,查看版本信息同时还包括status命令的信息

    每隔一秒输出当前mysql服务的状态信息
    mysqladmin -usystem -p'oralinux' -S /mysql/conf/mysql.sock -i 1 status
    每秒执行查询的数量
    mysqladmin -usystem -p'oralinux' -S /mysql/conf/mysql.sock -i 1 -r extended-status |grep -e "Com_select"

    <>PHPMyAdmin
    XAMPP:对Mysql、Perl、PHP封装各种相关的软件包,以及phpMyAdmin,下载地址:http://www.apachefriends.org/zh_cn/xampp.html
    1、解压: tar -xvfz xampp-linux -C /opt
    2、vi /opt/lampp/etc/extra/httpd-xampp.conf
    在/opt/lampp/phpmyadmin标签中(16-19行之间)增加一行:Require all granted。
    将LocationMatch标签中的第62行:Deny from all改为Allow from all 使其他服务器也能访问phpmyadmin
    3、启动服务:/opt/lampp/lampp start
    4、通过浏览器访问

    <>Mysql Workbench
    <>第三方管理工具:Sqlyog和Navicat

  • 相关阅读:
    阿里云oss前端javascript签名上传爬坑手册
    关于文件上传获取视频播放时长
    用js获取视频播放时长
    关于文件上传阿里云Oss
    两种方式实现图片上传在线预览
    关于input file img实时预览获取文件路径的问题
    关于input file 改样式的操作方式
    关于jquery attr()与prop() 的区别
    弹窗确认操作的业务逻辑与几种方式
    [LintCode] Flip Bits
  • 原文地址:https://www.cnblogs.com/datalife/p/6797283.html
Copyright © 2020-2023  润新知