今天我们要学习的是如何用MySQL 命令的方式来对账号进行管理,我们大家都知道在实际应用中MySQL 命令可以完成多种任务,以下的文章主要是对用MySQL 命令的方式来对账号进行管理的具体内容介绍。 手册上说 GRANT语句允许系统管理员创建MySQL用户账户,授予权
今天我们要学习的是如何用MySQL 命令的方式来对账号进行管理,我们大家都知道在实际应用中MySQL 命令可以完成多种任务,以下的文章主要是对用MySQL 命令的方式来对账号进行管理的具体内容介绍。
手册上说 “GRANT语句允许系统管理员创建MySQL用户账户,授予权限。”。但我无论怎么样也没有办法用这个命令创建用户账号。
我想增加一个新的测试用户,命令如下:
<ol class="dp-xml"> <li class="alt">MySQL<span><span class="tag">></span><span> GRANT ALL ON qyoa.* TO chy@localhost INDENTIFIED BY "123456"; </span></span> </li> <li><span>ERROR 1046 (3D000): No database selected </span></li> </ol>
后来上网找资料才发现这样写是错的,改成:
<ol class="dp-xml"> <li class="alt">MySQL<span><span class="tag">></span><span> GRANT ALL ON qyoa.* TO chy@localhost INDENTIFIED BY "123456"; </span></span> </li> <li><span>ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to </span></li> <li class="alt"> <span>your </span>MySQL<span> server version for the right syntax to use near 'INDEN TIFIED BY "123456"' at line 1 </span> </li> </ol>
网上有人也遇到这样的错误,有人如些回答:MySQL.user MySQL命令库应该选上.因为你执行的操作是修改权限表... 这个明白了你就可以直接操作这个表了.呵呵
(http://www.phpchina.com/html/54/t-51354.html)
可能是本人愚钝,怎么也看不明白这话什么意思。
只好一遍又一遍的试
<ol class="dp-xml"> <li class="alt">MySQL<span class="tag">></span> use MySQL; </li> <li>MySQL<span class="tag">></span><span> GRANT ALL ON qyoa.* TO chy@localhost INDENTIFIED BY "123456"; </span> </li> </ol>
错误提示同上面一样。
后来折腾了一两个小时,实现找不到问题出在那里。只好换过一种实现方式,
<ol class="dp-xml"> <li class="alt">MySQL<span><span class="tag">></span><span> CREATE USER chy@localhost IDENTIFIED BY '123456'; </span></span> </li> <li>MySQL<span class="tag">></span><span> grant all on qyoa.* to chy@localhost; </span> </li> </ol>
终于建好用户和分配好权限。难道只可以创建好账号才可以分配权限?
后来的我猜测得到证实,真的是要创建好账号才可以分配权限。杯具啊!就这样白白浪费了我好几个小时。
<ol class="dp-xml"><li class="alt">MySQL<span><span class="tag">></span><span> GRANT ALL ON qyoa.* TO chy@localhost INDENTIFIED BY "123456"; </span></span> </li></ol>
运行成功!
如果没有创建用户帐号,直接执行
<ol class="dp-xml"><li class="alt">MySQL<span><span class="tag">></span><span> grant all on qyoa.* to chy@localhost; </span></span> </li></ol>
会用如下错误信息
<ol class="dp-xml"><li class="alt"><span><span>ERROR 1133(42000) can 't find any matching row in the user table </span></span></li></ol>
或许是我本机的设置有问题吧,今天再执行
<ol class="dp-xml"><li class="alt">MySQL<span><span class="tag">></span><span>GRANT ALL ON qyoa.* TO chy1@localhost identified by "123456"; </span></span> </li></ol>
又可以正常执行了,搞不懂什么原因。难不成真的是我人品问题?
但将语句改成如下执行又出现问题:
<ol class="dp-xml"> <li class="alt">MySQL<span><span class="tag">></span><span> grant all on qyoa.* to chy@localhost; </span></span> </li> <li><span>ERROR 1133(42000) can 't find any matching row in the user table </span></li> </ol>
翻查MySQL命令手册得到如下资料:
”SQL服务器模式
模式定义MySQL应支持哪些SQL语法,以及应执行哪种数据验证检查。你可以用SELECT @@sql_mode语句查询当前的模式。
<ol class="dp-xml"><li class="alt"><span><span>· NO_AUTO_CREATE_USER </span></span></li></ol>
防止GRANT自动创建新用户,除非还指定了密码。
你还可以在启动后用SET [SESSION|GLOBAL] sql_mode='modes'语句设置sql_mode变量来更改SQL模式。
设置 GLOBAL变量时需要拥有SUPER权限,并且会影响从那时起连接的所有客户端的操作。设置SESSION变量只影响当前的客户端。
任何客户端可以随时更改自己的会话 sql_mode值。“
原来是设定了 sql 服务器模式。 sql_mode值 是保存在 my.ini 中,可以直接打开该文件修改后再重启服务,也可以用
SET SESSION sql_mode='STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' 进行更改。
测试:
<ol class="dp-xml"><li class="alt">MySQL<span><span class="tag">></span><span>SET SESSION </span><span class="attribute">sql_mode</span><span>=</span><span class="attribute-value">'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION'</span><span>; </span></span> </li></ol>
后再执行
<ol class="dp-xml"><li class="alt">MySQL<span><span class="tag">></span><span> grant all on qyoa.* to chy@localhost; </span></span> </li></ol>
创建空密码新账号成功!以上的相关内容就是对MySQL 账户管理 今天学习怎样用 MySQL 命令的方式来管理账号的介绍,望你能有所收获。

TograntpermissionstonewMySQLusers,followthesesteps:1)AccessMySQLasauserwithsufficientprivileges,2)CreateanewuserwiththeCREATEUSERcommand,3)UsetheGRANTcommandtospecifypermissionslikeSELECT,INSERT,UPDATE,orALLPRIVILEGESonspecificdatabasesortables,and4)

ToaddusersinMySQLeffectivelyandsecurely,followthesesteps:1)UsetheCREATEUSERstatementtoaddanewuser,specifyingthehostandastrongpassword.2)GrantnecessaryprivilegesusingtheGRANTstatement,adheringtotheprincipleofleastprivilege.3)Implementsecuritymeasuresl

ToaddanewuserwithcomplexpermissionsinMySQL,followthesesteps:1)CreatetheuserwithCREATEUSER'newuser'@'localhost'IDENTIFIEDBY'password';.2)Grantreadaccesstoalltablesin'mydatabase'withGRANTSELECTONmydatabase.TO'newuser'@'localhost';.3)Grantwriteaccessto'

The string data types in MySQL include CHAR, VARCHAR, BINARY, VARBINARY, BLOB, and TEXT. The collations determine the comparison and sorting of strings. 1.CHAR is suitable for fixed-length strings, VARCHAR is suitable for variable-length strings. 2.BINARY and VARBINARY are used for binary data, and BLOB and TEXT are used for large object data. 3. Sorting rules such as utf8mb4_unicode_ci ignores upper and lower case and is suitable for user names; utf8mb4_bin is case sensitive and is suitable for fields that require precise comparison.

The best MySQLVARCHAR column length selection should be based on data analysis, consider future growth, evaluate performance impacts, and character set requirements. 1) Analyze the data to determine typical lengths; 2) Reserve future expansion space; 3) Pay attention to the impact of large lengths on performance; 4) Consider the impact of character sets on storage. Through these steps, the efficiency and scalability of the database can be optimized.

MySQLBLOBshavelimits:TINYBLOB(255bytes),BLOB(65,535bytes),MEDIUMBLOB(16,777,215bytes),andLONGBLOB(4,294,967,295bytes).TouseBLOBseffectively:1)ConsiderperformanceimpactsandstorelargeBLOBsexternally;2)Managebackupsandreplicationcarefully;3)Usepathsinst

The best tools and technologies for automating the creation of users in MySQL include: 1. MySQLWorkbench, suitable for small to medium-sized environments, easy to use but high resource consumption; 2. Ansible, suitable for multi-server environments, simple but steep learning curve; 3. Custom Python scripts, flexible but need to ensure script security; 4. Puppet and Chef, suitable for large-scale environments, complex but scalable. Scale, learning curve and integration needs should be considered when choosing.

Yes,youcansearchinsideaBLOBinMySQLusingspecifictechniques.1)ConverttheBLOBtoaUTF-8stringwithCONVERTfunctionandsearchusingLIKE.2)ForcompressedBLOBs,useUNCOMPRESSbeforeconversion.3)Considerperformanceimpactsanddataencoding.4)Forcomplexdata,externalproc


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver Mac version
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Mac version
God-level code editing software (SublimeText3)
