mysql_config_editor 配置工具
mysql_config_editor工具能让你在一种加密的登录路径文件.mylogin.cnf中存储审核身份信息。在Windows中这个文件存储在%APPDATA%\MySQL目录中,在非Windows平台上存储在当前用户的home目录中。这种文件可以被MySQL客户端程序读取来获得连接MySQL服务器的审核身份信息。
没有加密的.mylogin.cnf登录路径文件由选项组组成。类似于其它的选项文件。在.mylogin.cnf文件中的每个选项组叫作"login path"登录路径,它是只允许特定选项的组:host,user,password,port和socket。可以把一个登录路径选项组认为是一组选项来指定使用那个用户来连接那个MySQL服务器的信息。下面是没有加密的登录路径信息的
例子:
[client]user=mydefaultnamepassword=mydefaultpasshost=127.0.0.1[mypath]user=myothernamepassword=myotherpasshost=localhost
当调用一个客户端程序连接MySQL服务器时,客户端使用.mylogin.cnf并结合其它的选项文件。它的优先级比其它的选项文件要高,但比在客户端命令行中显式指定的要低。
为了指定一个替代的登录路径文件名,设置MYSQL_TEST_LOGIN_FILE环境变量。这种变量通过mysql_config_editor,通过标准的MySQL客户端(mysql,mysqladmin等)工具和mysql-test-run.pl测试工具所识别。
程序以以下方式使用登录路径文件中的选项组:
.mysql_config_editor在你没有通过--login-path=name选项来显式指定登录路径时缺省情况下会使用client选项组。
.在没有使用--login-path选项的情况下,客户端程序将像从其它选项文件中读取信息一样从登录路径文件中读取选项组。比如:
shell>mysql
缺省情况下,mysql客户端程序将从其它的选项文件中读取[client]和[mysql]选项组,因此也会从登录路径文件中读取这些信息。
.使用--login-path选项,客户端程序额外从登录路径文件中讯取命名的登录路径。仍然与读取其它选项文件中的选项组一样。比如:
shell>mysql --login-path=mypath
mysql客户端程序将从其它选项文件中读取[client]和[mysql]选项组信息和从登录路径文件中读取[client]和[mysql]选项组信息。
.即使当--no-defaults选项被使用,客户端程序也会读取登录路径文件。这允许使用一种安全的方式来指定密码而不而在命令行中指定。
mysql_config_editor会对.mylogin.cnf文件进行加密因此它不能以明文方式被读取,并且当客户端程序解密时,它的内容只在内存中使用。通过这种方式,密码可以以非明文格式存储在文件中并且在以后的命令行或环境变量需要使用时不需要提供输入密码。mysql_config_editor提供了一个print命令来显示登录路径文件的内容,但即使在这种情况下,密码值也会被隐藏,这样就不会以其他用户可以看到的方式出现
通过mysql_config_editor加密阻止密码以明文方式出现在.mylogin.cnf文件中并通过阻止无意暴露密码提供了一种安全措施。例如,如果你在屏幕上以非加密方式来显示my.cnf选项文件中的信息时,它包含的任何密码对于任何人都是可见的。使用.mylogin.cnf文件不是这种情况。但是使用的加密不会阻止一个有决心的攻击者,你不应该认为它是不可攻破的。如果用户能够获得您机器上的系统管理权限来访问您的文件,那么他可以轻松地解密.mylogin.cnf文件
登录路径文件必须对当前用户可读和可写并且对其它用户来说不可以访问。否则,mysql_config_editor会忽略它,并且客户端程序不会使用它。
mysql_config_editor语法:
shell>mysql_config_editor[programoptions][command[commandoptions]]
如果登录路径文件不存在,mysql_config_editor会创建它。
mysql_config_editor命令有以下参数选项:
.program_options由通用的mysql_config_editor选项组成。
.command指示对.mylogin.cnf登录路径文件执行的操作。例如,set将写一个登录路径到文件中,remove将删除一个登录路径,print显示登录路径内容。
.command_options指示任何指定给命令的额外选项,比如登录路径名和登录路径所使用的值。
命令名在程序参数集中的位置很重要。例如,这些命令行具有相同的参数,但产生不同的结果:
[mysql@localhost~]$mysql_config_editor--helpsetmysql_config_editorVer1.0Distrib5.7.26,forLinuxonx86_64Copyright(c)2012,2019,Oracleand/oritsaffiliates.Allrightsreserved.OracleisaregisteredtrademarkofOracleCorporationand/oritsaffiliates.Othernamesmaybetrademarksoftheirrespectiveowners.MySQLConfigurationUtility.Usage:mysql_config_editor[programoptions][command[commandoptions]]-#,--debug[=#]Thisisanon-debugversion.Catchthisandexit.-?,--helpDisplaythishelpandexit.-v,--verboseWritemoreinformation.-V,--versionOutputversioninformationandexit.Variables(--variable-name=value)andbooleanoptions{FALSE|TRUE}Value(afterreadingoptions)-------------------------------------------------------------------------verboseFALSEWherecommandcanbeanyoneofthefollowing:set[commandoptions]Setsusername/password/hostname/socket/portforagivenloginpath(section).remove[commandoptions]Removealoginpathfromtheloginfile.print[commandoptions]Printalltheoptionsforaspecifiedloginpath.reset[commandoptions]Deletesthecontentsoftheloginfile.helpDisplaythisusage/helpinformation.[mysql@localhost~]$mysql_config_editorset--helpmysql_config_editorVer1.0Distrib5.7.26,forLinuxonx86_64Copyright(c)2012,2019,Oracleand/oritsaffiliates.Allrightsreserved.OracleisaregisteredtrademarkofOracleCorporationand/oritsaffiliates.Othernamesmaybetrademarksoftheirrespectiveowners.MySQLConfigurationUtility.Description:Writealoginpathtotheloginfile.Usage:mysql_config_editor[programoptions][set[commandoptions]]-?,--helpDisplaythishelpandexit.-h,--host=nameHostnametobeenteredintotheloginfile.-G,--login-path=nameNameoftheloginpathtouseintheloginfile.(Default:client)-p,--passwordPromptforpasswordtobeenteredintotheloginfile.-u,--user=nameUsernametobeenteredintotheloginfile.-S,--socket=nameSocketpathtobeenteredintologinfile.-P,--port=namePortnumbertobeenteredintologinfile.-w,--warnWarnandaskforconfirmationifsetcommandattemptstooverwriteanexistingloginpath(enabledbydefault).(Defaultstoon;use--skip-warntodisable.)Variables(--variable-name=value)andbooleanoptions{FALSE|TRUE}Value(afterreadingoptions)-------------------------------------------------------------------------host(Nodefaultvalue)login-pathclientuser(Nodefaultvalue)socket(Nodefaultvalue)port(Nodefaultvalue)warnTRUE
第一个命令行显示了通用的mysql_config_editor的帮助信息并且忽略了set命令。第二个命令行是显示了set命令的特定帮助信息。
假设想要建立一个client登录路径来定义你的缺省连接参数和额外的remote登录路径来连接远程服务器。想要记录以下信息:
.缺省情况,连接到本地服务器的用户名与密码为root和xxzx7817600
.连接到远程服务器的用户名与密码为root和123456
为了在.mylogin.cnf文件中设置登录路径,使用下面的set命令。每个命令单独一行执行并且根据提示输入相关的密码:
[mysql@localhost~]$mysql_config_editorset--login-path=client--host=192.168.1.250--user=root--passwordEnterpassword:[mysql@localhost~]$mysql_config_editorset--login-path=remote--host=192.168.1.251--user=root--password--port=33306Enterpassword:[mysql@localhost~]$
mysql_config_editor缺省情况下使用client登录路径,因此--login-path=client选项从第一个命令中可以被忽略而不会产生影响。
为了查询mysql_config_editor写入.mylogin.cnf文件的内容,执行print命令:
[mysql@localhost~]$mysql_config_editorprint--all[client]user=rootpassword=*****host=192.168.1.250[remote]user=rootpassword=*****host=192.168.1.251port=33306
print命令以一组行集合来显示每个登录路径,在方括号中的选项组头指示了登录路径名,接着是登录路径的选项值。密码值以星号出现不是以明文来显示。
如果你在执行print命令时不指定--all选项来显示所有的登录路径或不使用--login-path=name来显示指定的登录路径,如果存会client登录路径,那么缺省情况下print命令只会显示client登录路径。
[mysql@localhost~]$mysql_config_editorprint[client]user=rootpassword=*****host=192.168.1.250
通过上面的例子可以看到一个登录路径文件可以包含多个登录路径。使用这种方式,mysql_config_editor可以简单地多个个性化的登录路径来连接到不同的MySQL服务器或者使用不同的账号连接到指定的服务器。这些登录路径都可以在调用客户端程序时通过使用--login-path选项来使用。例如,为了连接到远程服务器,执行以下命令:
[mysql@localhost~]$mysql--login-path=remoteWelcometotheMySQLmonitor.Commandsendwith;or\g.YourMySQLconnectionidis56674Serverversion:5.7.26MySQLCommunityServer(GPL)Copyright(c)2000,2019,Oracleand/oritsaffiliates.Allrightsreserved.OracleisaregisteredtrademarkofOracleCorporationand/oritsaffiliates.Othernamesmaybetrademarksoftheirrespectiveowners.Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement.mysql>
上面的命令mysql从其它选项文件中读取[client]和[mysql]选项组并且从登录路径文件中读取[mysql]和[remote]选项组信息。
为了连接到本地服务器,执行以下命令
[mysql@localhost~]$mysql--login-path=clientWelcometotheMySQLmonitor.Commandsendwith;or\g.YourMySQLconnectionidis6Serverversion:5.7.26SourcedistributionCopyright(c)2000,2019,Oracleand/oritsaffiliates.Allrightsreserved.OracleisaregisteredtrademarkofOracleCorporationand/oritsaffiliates.Othernamesmaybetrademarksoftheirrespectiveowners.Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement.mysql>
因为缺省情况下mysql读取登录路径文件中的client和mysql登录路径,在这种情况下--login-path选项不会增加其它登录路径。因此上面的命令等价下面的命令:
[mysql@localhost~]$mysqlWelcometotheMySQLmonitor.Commandsendwith;or\g.YourMySQLconnectionidis7Serverversion:5.7.26SourcedistributionCopyright(c)2000,2019,Oracleand/oritsaffiliates.Allrightsreserved.OracleisaregisteredtrademarkofOracleCorporationand/oritsaffiliates.Othernamesmaybetrademarksoftheirrespectiveowners.Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement.mysql>
从登录路径文件读取的选项优先于从其他选项文件读取的选项。从登录路径文件中稍后出现的登录路径组读取的选项优先于从文件中较早出现的登录路径组读取的选项。
mysql_config_editor向登录路径文件增加登录路径的顺序就是创建它们的顺序,因此应该先创建更多的通用登录路径,后创建特定登录路径。如果想要在登录路径文件中移动一个登录路径,可以先删除它,然后再重新创建它。例如一个client登录路径很通用,因为所有的客户端程序将会读取它,而mysqldump登录路径只能由mysqldump程序来读取。后指定的选项会覆盖先指定的选项,因此以client,mysqldump顺序来创建登录路径,mysqldump程序能让mysqldump的特定选项覆盖client的选项。
在使用mysql_config_editor的set命令来创建一个登录路径时不需要指定所有可能选项值(主机名,用户名,密码,端口号,socket)。只有指定的值会被写入登录路径。任何丢失而在调用客户端程序连接服务器时所需要的选项可以在其它选项文件或命令行中批定。任何在命令行中指定的选项值会覆盖在登录路径文件或其它选项文件中所指定的选项值。例如,如果在remote登录路径中指定了端口号33306,现在假设远程服务器端口变为3306了,那么连接服务器命令如下:
[mysql@localhost~]$mysql--login-path=remote-P3306WelcometotheMySQLmonitor.Commandsendwith;or\g.YourMySQLconnectionidis56674Serverversion:5.7.26MySQLCommunityServer(GPL)Copyright(c)2000,2019,Oracleand/oritsaffiliates.Allrightsreserved.OracleisaregisteredtrademarkofOracleCorporationand/oritsaffiliates.Othernamesmaybetrademarksoftheirrespectiveowners.Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement.mysql>
命令行指定的端口号覆盖登录路径中指定的端口号
可以使用remove命令来删除登录路径或登录路径中的某些选项删除remote登录路径中的--port选项
[mysql@localhost~]$mysql_config_editorprint--login-path=remote[remote]user=rootpassword=*****host=192.168.1.250port=33306[mysql@localhost~]$mysql_config_editorremove--login-path=remote--port[mysql@localhost~]$mysql_config_editorprint--login-path=remote[remote]user=rootpassword=*****host=192.168.1.250
删除删除remote登录路径
[mysql@localhost~]$mysql_config_editorremove--login-path=remote[mysql@localhost~]$mysql_config_editorprint--login-path=remote
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。