[MySQL Reference Manual] 4 MYSQL Program

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介: 4 MYSQL Program 目录 4 MYSQL Program.. 1 4.3 MySQL Server和Server启动程序... 1 4.3.1 mysqld. 1 4.3.

4 MYSQL Program

目录

4 MYSQL Program.. 1

4.3 MySQL ServerServer启动程序... 1

4.3.1 mysqld. 1

4.3.2 mysqld_safe. 1

4.3.3 mysql.server. 1

4.3.4 mysqld_multi1

4.4 MySQL安装相关Program.. 2

4.4.1 comp_err. 2

4.4.2 mysqlbug. 2

4.4.3 mysql_install_db. 2

4.4.4 mysql_plugin. 2

4.4.5 mysql_secure_installation. 3

4.4.6 mysql_tzinfo_to_sql3

4.4.7 mysql_upgrade. 3

4.5 MySQL客户端程序... 4

4.5.1 mysql4

4.5.2 mysqladmin. 4

4.5.3 mysqlcheck. 4

4.5.4 mysqldump. 5

4.5.5 mysqlimport. 5

4.5.6 mysqlshow.. 5

4.5.7 mysqlslap. 6

4.6 MySQL管理和效率Programs. 6

4.6.1 innochecksum.. 6

4.6.2 myisam_ftdump. 6

4.6.3 myisamchk. 7

4.6.4 myisamlog. 7

4.6.5 myisampack. 7

4.6.6 mysql_config_editor. 7

4.6.7 mysqlaccess. 8

4.6.8 mysqlbinlog. 8

4.6.9 mysqldumpslow.. 9

4.6.10 mysqlhotcopy. 9

4.6.11 mysql_convert_table_format. 9

4.6.12 mysql_find_rows. 9

4.6.13 mysql_fix_extensions. 10

4.6.14 mysql_setpermission. 10

4.6.15 mysql_waitpid. 10

4.6.16 mysql_zap. 10

4.7 Mysql开发工具... 10

4.8 其他program.. 10

 

 

4.3 MySQL ServerServer启动程序

4.3.1 mysqld

mysqldmysql的服务程序,监听端口,通过系统变量和配置参数来影响mysqld的行为

4.3.2 mysqld_safe

mysqld_safe是在unix服务器上推荐的启动方法,mysqld_safe启动mysqld程序并且覆盖默认的行为和显示的指定启动什么服务。mysql_safe会读取配置文件为[mysqld],[server],[msqld_safe]里面的配置信息。

具体的mysqld_safe参数信息请看:

http://dev.mysql.com/doc/refman/5.6/en/mysqld-safe.html

 

另:在centos yum安装的mariadb,如果配置了配置文件,用service mysql start的时候有个坑,会无线的点(.)下去。

这个情况在这里有详细的描述:

http://www.oschina.net/question/1261643_149788?sort=time

4.3.3 mysql.server

mysql.server用于mac os x对于unix like 的系统基本不用。详细看:

http://dev.mysql.com/doc/refman/5.6/en/mysql-server.html

4.3.4 mysqld_multi

mysqld_multi用来管理多个mysqld进程的。可以启动关闭服务,或者报告当前状态。mysqld_multi会读取配置文件中[mysqldN]N是正数。

启动[mysqld7]

shell> mysqld_multi start 17

关闭[mysqld8],[mysqld10][mysqld13]:

shell> mysqld_multi stop 8,10-13

具体mysqld_multi的参数可以看:

http://dev.mysql.com/doc/refman/5.6/en/mysqld-multi.html

使用mysqld_multi要注意点:

1.在使用前要知道传递给mysqld的各个参数的意思,并注意不同的mysqld使用同一个数据文件夹可能带来的问题。

2.保证启动mysqld用户可以访问数据库文件夹

3.保证有相同的MYSQL账号来关闭mysqld并且有SHOUTDOWN权限。

4.每个socket文件和端口都不一样

5.每个mysqld都要有自己的pid文件

6.如果不是以root启动会有告警

配置文件的例子和详细信息可以看:

http://dev.mysql.com/doc/refman/5.6/en/mysqld-multi.html

4.4 MySQL安装相关Program

4.4.1 comp_err

comp_err编译错误信息文件,comp_err在编译产生errmsg.sys用于mysqld确定错误的显示。同时comp_err也会产生mysqld_error.h,mysqld_ername.h,sql_state.h

详细信息和参数:

http://dev.mysql.com/doc/refman/5.6/en/comp-err.html

4.4.2 mysqlbug

将会在mysql5.7被干掉,一般报告bug的方法是http://bugs.mysql.com/

4.4.3 mysql_install_db

mysql_install_db初始化MySQL数据文件夹和创建系统数据,也会创建以my-default.cnf为模板创建配置文件my.cnf如果my.cnf存在会创建my-new.cnfmysql 5.6.19测试后发现会在/usr/下生产配置文件,但是mariadb不会生成配置文件)。

调用方法:

shell> scripts/mysql_install_db --user=mysql \

         --basedir=/opt/mysql/mysql \

         --datadir=/opt/mysql/mysql/data

如果要修改innodb的一些设置,那么就可以现在my.cnf上面先设置比如innodb_data_file_path innodb_log_file_size

mysql_install_db参数和详细信息:

http://dev.mysql.com/doc/refman/5.6/en/mysql-install-db.html

4.4.4 mysql_plugin

mysql_plugin可以让mysql管理启动哪些插件要被mysql加载,mysql.plugin表决定了通过mysql_plugin加载哪些插件。在服务启动的时候mysql会加载mysql.plugin中的插件,当然也可以通过—plugin_name来指定插件。

更多关于插件安装可以查看:

 Section 5.1.8.1, “Installing and Uninstalling Plugins”

更多关于参数信息可以查看:

http://dev.mysql.com/doc/refman/5.6/en/mysql-plugin.html

4.4.5 mysql_secure_installation

mysql_secure_installation,可以:

1.设置root账号密码

2.可以设置root不让非localhost登陆

3.可以删除匿名账号

4.可以删除test账号

直接运行mysql_secure_installaiton,然后会进入交互模式进行设置。

4.4.6 mysql_tzinfo_to_sql

mysql_tzinfo_to_sql把时区信息加载到mysql,如:

shell> mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql

这些数据会被插入到mysql.timezhone*表里面

详细信息查看:

http://dev.mysql.com/doc/refman/5.6/en/mysql-tzinfo-to-sql.html

4.4.7 mysql_upgrade

mysql_upgrade检查当前mysql服务,所有数据库中不兼容的表。mysql_upgrade应该在每次升级之后都要运行一遍。检查不兼容问题。如果找到一个不兼容的表,会检查问题,如果问题被找到会试图修复这个表,如果无法修复那么之恩能够手动修复,修复表策略可以查看:Section 2.10.4, “Rebuilding or Repairing Tables or Indexes”

shell> mysql_upgrade [options]

mysql_upgrade之后,重启服务,让mysql_upgrade修复生效。mysql_upgrade其实是运行一下的过程:

mysqlcheck --no-defaults –databases --fix-db-names --fix-table-names mysql

mysqlcheck --no-defaults --check-upgrade –databases --auto-repair mysql

mysql < fix_priv_tables

mysqlcheck --no-defaults --all-databases --skip-database=mysql --fix-db-names --fix-table-names

mysqlcheck --no-defaults --check-upgrade --all-databases --skip-database=mysql --auto-repair

更详细的信息查看:

http://dev.mysql.com/doc/refman/5.6/en/mysql-upgrade.html

4.5 MySQL客户端程序

4.5.1 mysql

mysql是最常使用的工具之一弄能也十分的强大,主要有个特点是可以使用system或者/!来调用shell,如:

system ls

\! ls

help [content]查看服务端的帮助

关于mysql的参数,交互式命令等可以查看:

http://dev.mysql.com/doc/refman/5.6/en/mysql.html

4.5.2 mysqladmin

mysqladmin是一个管理工具,可以用来检查mysql的配置,当前状态,创建和删除数据库等。

shell> mysqladmin [options] command [command-arg] [command [command-arg]] ...

mysqladmin2部分组成:

1.选项,基本和mysql的选项差不多

2.命令,通过这些命令执行到mysqld

如,设置root密码

mysqladmin  -u root password ‘newpassword’

关于选项和命令的详细内容:

http://dev.mysql.com/doc/refman/5.6/en/mysqladmin.html

4.5.3 mysqlcheck

mysqlcheck用来维护表的,检查,修复,优化,分析表。当mysqlcheck执行的时候对表加锁(读锁),但是其他会话无法访问。对于大表mysqlcheck是很花时间的。mysqlcheckmyisamchk类似,但是也有不同:1.mysqld启动的时候才能运行,2.运行的时候不需要关闭服务。

对于用户来说mysqlcheck只是更加方便运行CHECK TABLE,REPAIR TABLE,ANALYZE TABLE,OPTIMIZE TABLE。由mysqlcheck决定需要运行哪个sql。有些存储引擎不不支持上面4sql,所有会报错。

shell> mysqlcheck [options] db_name [tbl_name ...]

shell> mysqlcheck [options] --databases db_name ...

shell> mysqlcheck [options] --all-databases

具体参数和命令:

http://dev.mysql.com/doc/refman/5.6/en/mysqlcheck.html

4.5.4 mysqldump

mysqldump是逻辑备份工具,备份产生sql语句结果可以放在txtxmlcvs中。mysqldump也是常用工具之一。mysqldump可以适用于小数据库但是大数据库用mysqldump备份在恢复的时候很坑爹。大数据库如果是innodb表可以考虑使用mysqlbackup,做物理备份,如果是myISAM表可以考虑使用mysqlhotcopy

例子:

备份数据库

shell> mysqldump db_name > backup-file.sql

恢复数据库:

shell> mysql db_name < backup-file.sql

shell> mysql -e "source /path-to-backup/backup-file.sql" db_name

迁移数据库:

shell> mysqldump --opt db_name | mysql --host=remote_host -C db_name

备份多个数据库:

shell> mysqldump --databases db_name1 [db_name2 ...] > my_databases.sql

更多的mysqldump的参数和选项:

http://dev.mysql.com/doc/refman/5.6/en/mysqldump.html

4.5.5 mysqlimport

mysqlimport导入工具,是通过LOAD DATA INFILE导入数据。

关于LOAD DATAINFILE可以查看:

http://dev.mysql.com/doc/refman/5.6/en/load-data.html

shell> mysqlimport [options] db_name textfile1 [textfile2 ...]

mysqlimport的选项很多,主要介绍2个:

列分隔符:

--fields-terminated-by=..., --fields-enclosed-by=..., --fields-optionally-enclosed-by=..., --fields-escaped-by=...,这些都是列分隔符

行分隔符:

--lines-terminated-by=...,是用方法: --lines-terminated-by="\r\n"和列分隔符一样。

其他参数请看:

http://dev.mysql.com/doc/refman/5.6/en/mysqlimport.html

4.5.6 mysqlshow

mysqlshow,就是使用show命令,show命令是比较常用的,所以mysqlshow没啥好说的。

具体信息查看:

http://dev.mysql.com/doc/refman/5.6/en/mysqlshow.html

4.5.7 mysqlslap

mysqlslap就是mysql的压测工具。如果能够搞到tpc-h测试标准的sql那么就可以对mysqltpc-h标准的测试了。

mysqlslap运行分3个阶段:

1.创建元数据,加载测试数据

2.测试

3.清理

有些例子:

mysqlslap --delimiter=";"

  --create="CREATE TABLE a (b int);INSERT INTO a VALUES (23)"

  --query="SELECT * FROM a" --concurrency=50 --iterations=200

 

mysqlslap --concurrency=5 --iterations=20
  --number-int-cols=2 --number-char-cols=3
  --auto-generate-sql

 

mysqlslap --concurrency=5
  --iterations=5 --query=query.sql --create=create.sql
  --delimiter=";"

一些选项可以看:

http://dev.mysql.com/doc/refman/5.6/en/mysqlslap.html

4.6 MySQL管理和效率Programs

4.6.1 innochecksum

Innochecksum打印innodb文件的checksum,通过读取innodb表空间文件计算每个pagechecksum然后和保存的checksum对比,报告不匹配的,不匹配说明page损坏。主要用于断电情况下表空间文件一致性检查。

 

Innochecksum不能服务启动的情况下使用,对于这种的表空间文件只能通过check table在表空间内的表来完成。

如果checksum出现不匹配,那么要通过还原备份来还原表空间。

shell> innochecksum [options] file_name

具体参数请看:

http://dev.mysql.com/doc/refman/5.6/en/innochecksum.html

4.6.2 myisam_ftdump

Myisam_ftdump显示myisam表中FULLTEXT索引信息。在运行myisam_ftdump之前如果服务还是启动的,那么闲运行FLUSH TABLES

shell> myisam_ftdump [options] tbl_name index_num

例:

myisam_ftdump /usr/local/mysql/data/test/mytexttable 1

详细参数:

http://dev.mysql.com/doc/refman/5.6/en/myisam-ftdump.html

4.6.3 myisamchk

Myisamchk获取myisam表信息,check,修复,优化表的工具。检查和修复表也可以使用CHECK TABLE REPAIR TABLE

Mysiamchk不带选项是,只做一些简单的表检查。

myisamchk [options] tbl_name ...

如果不再database目录,也可以

myisamchk /path/to/database_dir/*.MYI

具体参数“

http://dev.mysql.com/doc/refman/5.6/en/myisamchk.html

4.6.4 myisamlog

myisamlog处理myisam日志文件,调用方法:

shell> myisamlog [options] [file_name [tbl_name] ...]

具体参数:

http://dev.mysql.com/doc/refman/5.6/en/myisamlog.html

4.6.5 myisampack

myisampack压缩myisam表,对表的没列进行压缩,可以压缩40%70%。当表要使用的时候,读入内存会解压缩。当访问某一行的时候会带来不错的性能,因为只要解压缩一行。

对压缩表的访问尽量使用mmap如果不行或使用通用的读写文件操作。

注意:

1.最好在mysqld没有启动的时候压缩,如果启动了没有使用external lock最好不要使用压缩。

2.压缩后的表变成了只读

shell> myisampack [options] file_name ...

具体参数:

http://dev.mysql.com/doc/refman/5.6/en/myisampack.html

4.6.6 mysql_config_editor

mysql_config_editor会保存认证信息到一个加密的登陆文件(.mylogin.cnf)

shell> mysql_config_editor [program_options] command [command_options]

例:

shell> mysql_config_editor set --login-path=local
         --host=localhost --user=localuser --password
Enter password: enter password "localpass" here
shell> mysql_config_editor set --login-path=remote
         --host=remote.example.com --user=remoteuser --password
Enter password: enter password "remotepass" here

显示内容:

shell> mysql_config_editor print --all
[local]
user = localuser
password = *****
host = localhost
[remote]
user = remoteuser
password = *****
host = remote.example.com

mysql_config_editor命令和选项:

http://dev.mysql.com/doc/refman/5.6/en/mysql-config-editor.html

4.6.7 mysqlaccess

mysqlaccess用来诊断给定hostuser,数据库的访问权限。

shell> mysqlaccess [host_name [user_name [db_name]]] [options]

具体选项:

http://dev.mysql.com/doc/refman/5.6/en/mysqlaccess.html

4.6.8 mysqlbinlog

mysqlbinlog是比较常用的工具,可以查看binlog的内容(也就是事务日志解析工具)。

mysqlbinlog [options] log_file ...

例:

mysqlbinlog binlog.0000003

除了sql之外还会显示一下信息:

# at 141
#100309  9:28:36 server id 123  end_log_pos 245
  Query thread_id=3350  exec_time=11  error_code=0

atat所在行的行数

时间:发送sql的时间

server idserver id主要被用在数据库复制,用来唯一标示primarysecondary

end log pos:下一个日志开始的位子

thread id:标示由那个thread执行

exec_time:master中是执行时间,在slave中是在slave的完成时间减去master的开始事件。

error_code:执行返回的结果。

mysqlbinlog的结果是可以重现被执行的,具体:Section 7.5, “Point-in-Time (Incremental) Recovery Using the Binary Log”.

具体参数:

http://dev.mysql.com/doc/refman/5.6/en/mysqlbinlog.html

4.6.9 mysqldumpslow

mysqldumpshlow,显示slowlog的信息。slow根据参数配置产生日志。

shell> mysqldumpslow [options] [log_file ...]

具体参数:

http://dev.mysql.com/doc/refman/5.6/en/mysqldumpslow.html

4.6.10 mysqlhotcopy

mysqlhotcopy是一个perl脚本,使用FLUSH TABLES,LOCK TABLEScpscp备份数据库。只能备份myisamARCHIVE的表。

shell> mysqlhotcopy db_name [/path/to/new_directory]
shell> mysqlhotcopy db_name_1 ... db_name_n /path/to/new_directory

也可以用正则表达式,备份数据库中的表:

shell> mysqlhotcopy db_name./regex/

~前缀排除表名

shell> mysqlhotcopy db_name./~regex/

具体参数:

http://dev.mysql.com/doc/refman/5.6/en/mysqlhotcopy.html

4.6.11 mysql_convert_table_format

把数据库中的表转化为指定的存储引擎。

shell> mysql_convert_table_format [options]db_name

具体参数:

http://dev.mysql.com/doc/refman/5.6/en/mysql-convert-table-format.html

4.6.12 mysql_find_rows

mysql_find_rows根据正则表达式,提取文件中的sql语句。

具体参数:

http://dev.mysql.com/doc/refman/5.6/en/mysql-find-rows.html

4.6.13 mysql_fix_extensions

规范表文件后缀名,把.frm, .myd, .myi, .isd,  .ism ,重命名为.frm, .MYD, .MYI, .ISD, .ISM

shell> mysql_fix_extensions data_dir

具体查看:

http://dev.mysql.com/doc/refman/5.6/en/mysql-fix-extensions.html

 

4.6.14 mysql_setpermission

mysql_setpermissionPerl脚本,用于交互式的设置mysql grant表的权限。

shell> mysql_setpermission [options]

mysql_setpermission会读取配置文件中[client][perl]

具体选项:

http://dev.mysql.com/doc/refman/5.6/en/mysql-setpermission.html

4.6.15 mysql_waitpid

mysql_waitpid,中断进程,并等待进程中断。只能适用于unixunix-like系统

shell> mysql_waitpid [options] pid wait_time

具体选项:

http://dev.mysql.com/doc/refman/5.6/en/mysql-waitpid.html

4.6.16 mysql_zap

mysql_zap删除模式匹配到的所有进程。

shell> mysql_zap [-signal] [-?Ift] pattern

具体参数:

http://dev.mysql.com/doc/refman/5.6/en/mysql-zap.html

4.7 Mysql开发工具

4.8 其他program

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
3月前
|
SQL 数据采集 关系型数据库
如何解决MySQL报错 You have an error in your SQL syntax; check the manual that corresponds to your MySQL?
如何解决MySQL报错 You have an error in your SQL syntax; check the manual that corresponds to your MySQL?
|
6月前
|
SQL 关系型数据库 MySQL
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
错误提示: Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; che
88 0
|
4月前
|
SQL 关系型数据库 MySQL
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
27 0
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
|
8月前
|
SQL 关系型数据库 MySQL
check the manual that corresponds to your MySQL server version for the right syntax to use near lin
注意这种一般情况下是语法问题,说明mysql的各种语句还是不够熟练, (1)看表名是不是使用了Mysql的关键字,如果是,请立马改掉; (2)语句给出哪里错误,如我的题目中给出“near”,说明在那附近有问题。 (3)检查mybatis中mapper里sql语句占位符是否写对,我的问题是将#{name}写成了#(name),尴尬。
133 0
|
10月前
|
SQL 关系型数据库 MySQL
修改mysql的密码时遇到问题ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corre
修改mysql的密码时遇到问题ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corre
|
SQL 关系型数据库 MySQL
MySQL - [ERR] 1064 - You have an error in your SQL syntax check the manual……
MySQL - [ERR] 1064 - You have an error in your SQL syntax check the manual……
185 0