mysql常用命令,授权和撤销操作

授予数据库名称权限。
数据库表对用户的权限:insert为添加,delete为删除,select为检查,update为更改,create为创建,drop为删除。
示例:grantselectonusertoxhk表示将用户数据库的查询权限授予xhk用户。
可以在用户后面添加@'ip。
地址'identifiedby'密码'例如:grantallon*.*toxhk@'127.0.0.1'identifyby'123456'表示将所有数据库的所有权限授权给用户xhk,允许用户xhk通过IP地址127.0.0.1进行远程登录。
0.1,并设置用户密码为123456刷新权限:flushprivileges//授权后完成后,必须刷新权限才能生效。
普通用户一般增删改查修改:grantselectontest.*toxhk@'%'//表示将test数据库下所有表的查询权限授予xhk用户grantinsertontest.usertoxhk@'%'//表示将test数据库下所有表的查询权限授予xhk用户将test数据库下的user表的查询权限授予xhk用户grantupdateontest.*toxhk@'%';grantdeleteontest.*toxhk@'%';数据库开发人员创建表、索引、视图、存储过程、函数等的权限:grantcreateontest.*toxhk@'192.168.0.%'grantalterontest.*toxhk@'192.168.0.%'grantdropontest.*toxhk@'192.168.0.%'//192.168.0.%表示允许远程连接的IP地址。
如果不想限制链接的IP地址,设置为“%”即可grantallprivilegesontestdbtodba@'localhost',其中关键字“privileges”可省略。
grantallon*.*todba@'localhost'grantselecton*.*todba@localhost;--dba可以查询MySQL中所有数据库中的表。
grantallon*.*todba@localhost;--dba可以管理MySQL中的所有数据库grantselectontestdb.*todba@localhost;--dba可以查询testdb中的表。
grantselect,插入,更新,删除eontestdb.orderstodba@localhost;grantselect(user_id,用户名)onsmp.userstomo_user@'%'identifiedby'123345';grantselectonsmp.mo_smstomo_user@'%'identifiedby'123345';grantselect(id,se,rank)ontestdb.apache_logtodba@localhost;grantexecuteonproceduretestdb.pr_addto'dba'@'localhost';grantexecuteonfunctiontestdb.fn_addto'dba'@'localhost';showgrants;showgrantsfordba@localhost;revokeallon*.*fromdba@localhost;grant,撤销用户权限后,仅该用户已重新连接MySQL数据库以使权限生效。
grantselectontestdb.*todba@localhostwithgrantoption;这个功能一般不使用。
实践中,数据库权限最好由DBA统一管理。

写出5条使用mysqladmin命令行工具的语句

查看MySQL服务器状态:bashmysqladmin-uroot-pstatus该命令会要求你输入MySQLroot用户的密码,然后显示MySQL服务器当前的状态信息,包括版本、运行时间、连接数等关键指标。
将。
,ETC。
重启MySQL服务:bashsudomysqladmin-uroot-pshutdownsudosystemctlstartmysql首先使用mysqladmin命令安全关闭,还有-u和-p参数(-p一般在密码后面,但出于安全考虑,密码(不写)直接在此处)使用关闭MySQL服务。
然后,通过系统服务管理器(例如systemd)启动MySQL服务。
注意,重启操作需要相应的系统权限。
刷新权限:bashmysqladmin-uroot-pflush-privileges该命令用于重新加载授权表(即执行FLUSHPRIVILEGESSQL命令),通常在修改MySQL的权限设置后执行,以确保更改立即生效。

创建新数据库:bashmysqladmin-uroot-pcreatenew_database_name使用mysqladmin命令和创建选项轻松创建新数据库。
您需要将new_database_name替换为要创建的数据库的名称。
删除数据库:bashmysqladmin-uroot-pdropold_database_name与创建数据库不同,此命令允许您删除现有数据库。
请小心,因为一旦执行,数据库及其所有数据将被永久删除。
将old_database_name替换为要删除的数据库的名称。