创建mysql 账号 赋予权限 只读权限,创建存储过程执行权限 您所在的位置:网站首页 mysql给用户权限 创建mysql 账号 赋予权限 只读权限,创建存储过程执行权限

创建mysql 账号 赋予权限 只读权限,创建存储过程执行权限

2023-09-02 00:33| 来源: 网络整理| 查看: 265

目录

 

创建mysql 账号 赋予权限 只读权限,创建存储过程执行权限

1、创建mysql 账号 赋予权限

2、赋予权限,myuser账号,某个IP下的所有权限;

3、赋予权限,root账号,所有IP下的所有权限;

4、赋予权限 只读权限

5、赋予存储过程执行权限;

6、使授权生效:

7、撤销已经赋予用户的权限:

8、案例脚本

9、MYSQL创建存储过程

Linux下修改账户密码

一. root 权限修改用户名密码:

二. 非root 权限修改用户名密码:

创建mysql 账号 赋予权限 只读权限,创建存储过程执行权限 1、创建mysql 账号 赋予权限

create user 'myuser'@'%' identified by 'mypassword';

2、赋予权限,myuser账号,某个IP下的所有权限;

GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.3' IDENTIFIED BY 'mypassword' ;

3、赋予权限,root账号,所有IP下的所有权限;

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mypassword' ;

4、赋予权限 只读权限

GRANT SELECT ON *.* TO 'bigdata'@'%' IDENTIFIED BY "123456";

Query OK, 0 rows affected (0.00 sec)

5、赋予存储过程执行权限;

grant execute on xrdatest.* TO bpmtest@'%' ;

6、使授权生效:

mysql> FLUSH PRIVILEGES;

7、撤销已经赋予用户的权限:

revoke 跟 grant 的语法差不多,只需要把关键字 “to” 换成 “from” 即可:

mysql>grant all on *.* to dba@localhost;

mysql>revoke all on *.* from dba@localhost;

8、案例脚本 [root@hostmod ~]# mysql -uroot -pP@ssw0rd#200 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 101972 Server version: 5.7.24 MySQL Community Server (GPL) Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> showdatabases; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'showdatabases' at line 1 mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | bi | | mysql | | performance_schema | | source | | sys | | xrdatest | | yqwy | | yyparking | +--------------------+ 9 rows in set (0.00 sec) mysql> select user,host from mysql.user; +---------------+-----------+ | user | host | +---------------+-----------+ | root | % | | mysql.session | localhost | | mysql.sys | localhost | | root | localhost | +---------------+-----------+ 4 rows in set (0.00 sec) mysql> create user 'bpmtest'@'%' identified by 'P@ssw0rd@bpm'; Query OK, 0 rows affected (0.01 sec) mysql> select user,host from mysql.user; +---------------+-----------+ | user | host | +---------------+-----------+ | bpmtest | % | | root | % | | mysql.session | localhost | | mysql.sys | localhost | | root | localhost | +---------------+-----------+ 5 rows in set (0.00 sec) mysql> grant execute on xrdatest.complain_sp to bpmtest@'%' identified by 'P@ssw0rd@bpm'; ERROR 1144 (42000): Illegal GRANT/REVOKE command; please consult the manual to see which privileges can be used mysql> grant execute procedure on xrdatest.complain_sp to bpmtest@'%' identified by 'P@ssw0rd@bpm'; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'procedure on xrdatest.complain_sp to bpmtest@'%' identified by 'P@ssw0rd@bpm'' at line 1 mysql> grant select,execute procedure on xrdatest.complain_sp to bpmtest@'%' identified by 'P@ssw0rd@bpm'; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'procedure on xrdatest.complain_sp to bpmtest@'%' identified by 'P@ssw0rd@bpm'' at line 1 mysql> grant select,execute procedure on `xrdatest`.`complain_sp` to bpmtest@'%' identified by 'P@ssw0rd@bpm'; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'procedure on `xrdatest`.`complain_sp` to bpmtest@'%' identified by 'P@ssw0rd@bp' at line 1 mysql> ^C mysql> grant execute on xrdatest.* TO bpmtest@'%' ; Query OK, 0 rows affected (0.01 sec) mysql> Connection closed by foreign host. mysql -uroot -pSuplus#1234 create user 'crmtest'@'%' identified by 'P@ssw0rd@bpm'; 授权执行: grant execute on data_centre_test.* TO crmtest@'%' ; create user 'dsjparking'@'%' identified by 'P@ssw0rd888'; 授权只读: GRANT SELECT ON *.* TO 'dsjparking'@'%' IDENTIFIED BY 'P@ssw0rd888'; FLUSH PRIVILEGES; create user 'crmbpm'@'%' identified by 'P@ssw0rd@bpm'; grant execute on data_centre.* TO crmbpm@'%' ; 9、MYSQL创建存储过程   ----创建存储过程---- CREATE PROCEDURE `test`(t1 varchar(10), t2 varchar(10), code varchar(50),uname varchar(50)) BEGIN if(TIMESTAMPDIFF(MONTH,t1,t2) < 2 AND TIMESTAMPDIFF(MONTH,t1,t2) > -2) then select u.* from yjwy_pub_user u where IF(ISNULL(code), true, user_code_ like concat('%',code,'%')) and IF(isnull(uname), true, user_name_=uname); ELSE select u.* from yjwy_pub_user u where false; end IF; END; 调用存储过程:call test('2020-09-01','2020-09-17','liaojuncai','廖俊才'); -----投诉------ complain_sp DROP PROCEDURE IF EXISTS `complain_sp`; CREATE PROCEDURE `complain_sp`(project_id varchar(50),start_date varchar(30), end_date varchar(30) ) BEGIN if(TIMESTAMPDIFF(DAY,start_date,end_date)) =concat(start_date,' 00:00:00') and t.complain_createdatetime=concat(start_date,' 00:00:00') and t.complain_createdatetime


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有