当前位置:   article > 正文

8月5日学习笔记 glibc安装与安全用户角色权限

8月5日学习笔记 glibc安装与安全用户角色权限

一,glibc安装

https://www.mysql.com/ 官⽹
https://downloads.mysql.com/archives/community/
https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.33-li
nux-glibc2.12-x86_64.tar
安装步骤

1.安装依赖库

  1. [root@localhost ~]# yum list installed |grep libaio
  2. libaio.x86_64 0.3.109-
  3. 13.el7 @anaconda
  4. [root@localhost ~]#

2.解压查看

  1. [root@localhost ~]# ls
  2. mysql-8.0.33-linux-glibc2.12-x86_64.tar
  3. [root@localhost ~]# tar -xvf mysql-8.0.33-linuxglibc2.12-x86_64.tar
  4. mysql-8.0.33-linux-glibc2.12-x86_64.tar.xz
  5. mysql-router-8.0.33-linux-glibc2.12-x86_64.tar.xz
  6. [root@localhost ~]# tar -xvf mysql-8.0.33-linuxglibc2.12-x86_64.tar.xz
  7. mysql-8.0.33-linux-glibc2.12-x86_64
  8. [root@localhost ~]# ls mysql-8.0.33-linuxglibc2.12-x86_64/
  9. bin docs include lib LICENSE man README
  10. share support-files
https://dev.mysql.com/doc/refman/8.0/en/binary-installation.html#
binary-installation-layout

3.创建⽤户

  1. [root@localhost ~]# useradd -r -s /sbin/nologin
  2. mysql
  3. [root@localhost ~]# id mysql
  4. uid=27(mysql) gid=27(mysql) 组=27(mysql)

4.清空其他环境 mariadb

[root@localhost ~]# rm -rf /etc/my.cnf

5.将解压文件放置在根目录下

  1. [root@localhost ~]# mv mysql-8.0.33-linuxglibc2.12-x86_64/ /mysql8
  2. [root@localhost ~]# ls /mysql8/
  3. bin docs include lib LICENSE man README
  4. share support-files

6.切换mysql8⽬录,创建⼀个mysq-files

  1. cd /mysql8/
  2. mkdir mysql-files

7.修改mysql-files⽂件权限750和所属 mysql

  1. [root@localhost mysql8]# chown mysql:mysql mysqlfiles/
  2. [root@localhost mysql8]# chmod 750 mysql-files/
  3. [root@localhost mysql8]# ls -l
  4. 总⽤量 296
  5. drwxr-xr-x. 2 7161 31415 4096 317 2023 bin
  6. drwxr-xr-x. 2 7161 31415 38 317 2023 docs
  7. drwxr-xr-x. 3 7161 31415 4096 317 2023
  8. include
  9. drwxr-xr-x. 6 7161 31415 201 317 2023 lib
  10. -rw-r--r--. 1 7161 31415 284945 317 2023
  11. LICENSE
  12. drwxr-xr-x. 4 7161 31415 30 317 2023 man
  13. drwxr-x---. 2 mysql mysql 6 83 22:30
  14. mysql-files
  15. -rw-r--r--. 1 7161 31415 666 317 2023
  16. README
  17. drwxr-xr-x. 28 7161 31415 4096 317 2023
  18. share
  19. drwxr-xr-x. 2 7161 31415 77 317 2023
  20. support-files

8.初始化数据库,找到初始密码

  1. [root@localhost mysql8]# ./bin/mysqld --initialize
  2. --user=mysql --basedir=/mysql8
  3. 2024-08-03T14:34:53.993391Z 0 [System] [MY-013169]
  4. [Server] /mysql8/bin/mysqld (mysqld 8.0.33)
  5. initializing of server in progress as process 2236
  6. 2024-08-03T14:34:54.003043Z 1 [System] [MY-013576]
  7. [InnoDB] InnoDB initialization has started.
  8. 2024-08-03T14:34:55.674077Z 1 [System] [MY-013577]
  9. [InnoDB] InnoDB initialization has ended.
  10. 2024-08-03T14:34:58.133984Z 6 [Note] [MY-010454]
  11. [Server] A temporary password is generated for
  12. root@localhost: .I//GqI,Z2-k

9.查看是否初始化成功过,可以看⽂件夹中

是否有data⽂件夹

  1. [root@localhost mysql8]# ls
  2. bin docs lib man README
  3. support-files
  4. data include LICENSE mysql-files share

10.设置ssl安全加密连接 敏感数据

  1. [root@localhost mysql8]# ls ./bin/*ssl*
  2. ./bin/mysql_ssl_rsa_setup
  3. [root@localhost mysql8]# ./bin/mysql_ssl_rsa_setup
  4. --datadir=/mysql8/data
  5. [root@localhost mysql8]# ls ./data/
  6. auto.cnf #ib_16384_1.dblwr mysql.ibd
  7. sys
  8. ca-key.pem ib_buffer_pool
  9. performance_schema undo_001
  10. ca.pem ibdata1
  11. private_key.pem undo_002
  12. client-cert.pem #innodb_redo
  13. public_key.pem
  14. client-key.pem #innodb_temp servercert.pem
  15. #ib_16384_0.dblwr mysql serverkey.pem

11.其他配置

  1. [root@localhost mysql8]# cp supportfiles/mysql.server /etc/init.d/mysql8
  2. [root@localhost mysql8]# ls /etc/init.d/mysql8
  3. /etc/init.d/mysql8
  4. [root@localhost mysql8]# ls /etc/init.d/
  5. functions mysql8 mysql8ls netconsole network
  6. README
  7. [root@localhost mysql8]#
  8. # 默认情况下,启动⽂件认识安装⽬录在/usr/local/⽬录下
  9. [root@localhost mysql8]# sed -n '/^basedir=/p'
  10. /etc/init.d/mysql8
  11. basedir=
  12. [root@localhost mysql8]# sed -i
  13. '/^basedir=/cbasedir=/mysql8' /etc/init.d/mysql8
  14. [root@localhost mysql8]# sed -n '/^basedir=/p'
  15. /etc/init.d/mysql8
  16. basedir=/mysql8
  17. [root@localhost mysql8]# sed -n '/^datadir=/p'
  18. /etc/init.d/mysql8
  19. datadir=
  20. [root@localhost mysql8]# sed -i
  21. '/^datadir=/cdatadir=/mysql8/data'
  22. /etc/init.d/mysql8
  23. [root@localhost mysql8]# sed -n '/^datadir=/p'
  24. /etc/init.d/mysql8
  25. datadir=/mysql8/data
  26. [root@localhost mysql8]#

12.启动服务 不能使⽤systemctl

  1. ot@localhost mysql8]# service mysql8 start
  2. Starting MySQL.Logging to
  3. '/mysql8/data/localhost.localdomain.err'.
  4. .. SUCCESS!
  5. [root@localhost mysql8]# ls /mysql8/data/*.err
  6. /mysql8/data/localhost.localdomain.err
  7. # 启动成功后会⽣成err⽇志⽂件,多看看,了解启动的详细原因

13.常⻅问题

  1. 1. 为什么要删除/etc/my.cnf⽂件
  2. ```
  3. 数据库初始化时候,会⾃动找my.cnf配置,但是原有的mariadb配
  4. 置⽂件,会失败
  5. ```
  6. 2. mysql-files⽂件夹
  7. ```
  8. ⽬前么有⽤,必须创建,可能导致⽆法启动,数据的备份和还原,导
  9. ⼊和到处所指定的默认⽬录
  10. ```
  11. 3. 判断数据库初始化成功
  12. ```
  13. 数据库的安装容易出错的地⽅是初始化,⽆法正常启动,确认⽅式
  14. 安装⽬录下是否⽣成data⽬录
  15. ```
  16. 4. 为什么要修改mysql.server放在/etc/init.d⽬录下
  17. ```
  18. 不放也可以,但是就⽆法使⽤service mysql8 start启动
  19. 只能使⽤bin/mysqld可执⾏⽂件启动
  20. ```
  21. 5. 为什么需要修改basedir和datadir
  22. ```
  23. glibc是⼆进制绿⾊版本,默认配置很多,需要修改
  24. ```
  25. 6. 开机启动
  26. ```shell
  27. [root@localhost mysql8]# chkconfig --list
  28. 注:该输出结果只显示 SysV 服务,并不包含
  29. 原⽣ systemd 服务。SysV 配置数据
  30. 可能被原⽣ systemd 配置覆盖。
  31. 要列出 systemd 服务,请执⾏ 'systemctl listunit-files'
  32. 查看在具体 target 启⽤的服务请执⾏
  33. 'systemctl list-dependencies [target]'
  34. netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关
  35. network 0:关 1:关 2:开 3:开 4:开 5:开 6:关
# 添加开机启动
[root@localhost mysql8]# chkconfig --add mysql8
  1. #查看启动该列表
  2. [root@localhost mysql8]# chkconfig --list
  3. 注:该输出结果只显示 SysV 服务,并不包含
  4. 原⽣ systemd 服务。SysV 配置数据
  5. 可能被原⽣ systemd 配置覆盖。
  6. 要列出 systemd 服务,请执⾏ 'systemctl listunit-files'
  7. 查看在具体 target 启⽤的服务请执⾏
  8. 'systemctl list-dependencies [target]'
  9. mysql8 0:关 1:关 2:开 3:开 4:开 5:开 6:关
  10. netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关
  11. network 0:关 1:关 2:开 3:开 4:开 5:开 6:关
  12. # 启动2345
  13. [root@localhost mysql8]# chkconfig mysql8 on
  14. [root@localhost mysql8]# chkconfig --list
  15. 注:该输出结果只显示 SysV 服务,并不包含
  16. 原⽣ systemd 服务。SysV 配置数据
  17. 可能被原⽣ systemd 配置覆盖。
  18. 要列出 systemd 服务,请执⾏ 'systemctl listunit-files'
  19. 查看在具体 target 启⽤的服务请执⾏
  20. 'systemctl list-dependencies [target]'
  21. mysql8 0:关 1:关 2:开 3:开 4:开 5:开 6:关
  22. netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关
  23. network 0:关 1:关 2:开 3:开 4:开 5:开 6:关
  24. # 3是字符界⾯,5是图形界⾯
  25. ```## 14 .mysql glibc版本后续设置
  26. 1. 修改密码1
  27. ```shell
  28. [root@localhost mysql8]# ./bin/mysqladmin -uroot
  29. password '123' -p
  30. Enter password:
  31. mysqladmin: [Warning] Using a password on the
  32. command line interface can be insecure.
  33. Warning: Since password will be sent to server
  34. in plain text, use ssl connection to ensure
  35. password safety.
[root@localhost mysql8]# ./bin/mysql -uroot -p
Enter password: # 输⼊123
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.33 MySQL Community Server - GPL
  1. Copyright (c) 2000, 2023, Oracle and/or its
  2. affiliates.
  3. Oracle is a registered trademark of Oracle
  4. Corporation and/or its
  5. affiliates. Other names may be trademarks of
  6. their respective
  7. owners.
  8. Type 'help;' or '\h' for help. Type '\c' to
  9. clear the current input statement.
  10. mysql>
  1. 2. 修改密码2
  2. ```shell
  3. mysql> set password='456';
  4. Query OK, 0 rows affected (0.02 sec)
  5. mysql> flush privileges;
  6. Query OK, 0 rows affected (0.01 sec)
[root@localhost mysql8]# ./bin/mysql -uroot -p456
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 11
Server version: 8.0.33 MySQL Community Server - GPL
  1. Copyright (c) 2000, 2023, Oracle and/or its
  2. affiliates.
  3. Oracle is a registered trademark of Oracle
  4. Corporation and/or its
  5. affiliates. Other names may be trademarks of
  6. their respective
  7. owners.
  8. Type 'help;' or '\h' for help. Type '\c' to
  9. clear the current input statement.
  10. mysql>
  11. ```
  1. 3. 将mysql的bin⽬录添加到环境变量中
  2. ```shell
  3. [root@localhost mysql8]# sed -i '$aexport
  4. PATH=/mysql8/bin/:$PATH' /etc/profile
  5. [root@localhost mysql8]# sed -n '$p'
  6. /etc/profile
  7. export PATH=/mysql8/bin/:$PATH
  8. [root@localhost mysql8]# source /etc/profile
  9. [root@localhost mysql8]# which mysql
  10. /mysql8/bin/mysql
  11. [root@localhost mysql8]# mysqld
  12. 2024-08-03T15:53:05.871244Z 0 [System] [MY-
  13. 010116] [Server] /mysql8/bin/mysqld (mysqld 8.0.33)
  14. starting as process 2861
  15. 2024-08-03T15:53:05.874283Z 0 [ERROR] [MY-
  16. 010123] [Server] Fatal error: Please read
  17. "Security" section of the manual to find out how to
  18. run mysqld as root!
  19. 2024-08-03T15:53:05.874333Z 0 [ERROR] [MY-
  20. 010119] [Server] Aborting
  21. 2024-08-03T15:53:05.874776Z 0 [System] [MY-
  22. 010910] [Server] /mysql8/bin/mysqld: Shutdown
  23. complete (mysqld 8.0.33) MySQL Community Server -
  24. GPL.
  25. [root@localhost mysql8]#
  26. ```
  1. 4. 配置⽂件
  2. ```shell
  3. [root@localhost mysql8]# fg
  4. vim ./my.cnf
  5. [mysqld]
  6. basedir=/mysql8
  7. datadir=/mysql8/data
  8. socket=/tmp/mysql.sock
#重启服务
[root@localhost mysql8]# service mysql8 restart
Shutting down MySQL.. SUCCESS!
Starting MySQL.. SUCCESS!
  1. # 查看套接字⽂件
  2. [root@localhost mysql8]# ll /tmp/
  3. 总⽤量 12
  4. -rwx------. 1 root root 836 82 23:02 ksscript-64N_oN
  5. srwxrwxrwx. 1 mysql mysql 0 84 00:02
  6. mysql.sock
  7. -rw-------. 1 mysql mysql 5 84 00:02
  8. mysql.sock.lock
  9. srwxrwxrwx. 1 mysql mysql 0 84 00:02
  10. mysqlx.sock
  11. -rw-------. 1 mysql mysql 5 84 00:02
  12. mysqlx.sock.lock
  13. drwx------. 3 root root 17 83 20:49
  14. systemd-private-23259a7f757e44ec9ab58b88e07ceefachronyd.service-poengE
  15. -rw-------. 1 root root 0 82 22:58
  16. yum.log

# 有套接字⽂件,就可以链接mysql服务
[root@localhost mysql8]# mysql -uroot -p456
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 8
Server version: 8.0.33 MySQL Community Server - GPL
Copyright (c) 2000, 2023, Oracle and/or its
affiliates.
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>
```

14. 安全配置 ⽣产环境

  1. [root@localhost mysql8]# mysql_secure_installation
  2. # ⼀路y下去 改密码,不允许远程等等
  3. Securing the MySQL server deployment.
  4. Enter password for user root:
  5. VALIDATE PASSWORD COMPONENT can be used to test
  6. passwords
  7. and improve security. It checks the strength of
  8. password
  9. and allows the users to set only those passwords
  10. which are
  11. secure enough. Would you like to setup VALIDATE
  12. PASSWORD component?
  13. Press y|Y for Yes, any other key for No:
  14. Using existing password for root.
  15. Change the password for root ? ((Press y|Y for Yes,
  16. any other key for No) : y
  17. New password:
  18. Re-enter new password:
  19. Sorry, passwords do not match.
  20. New password:
  21. Re-enter new password:
  22. By default, a MySQL installation has an anonymous
  23. user,
  24. allowing anyone to log into MySQL without having to
  25. have
  26. a user account created for them. This is intended
  27. only for
  28. testing, and to make the installation go a bit
  29. smoother.
  30. You should remove them before moving into a
  31. production
  32. environment.
  33. Remove anonymous users? (Press y|Y for Yes, any
  34. other key for No) : y
  35. Success.
  36. Normally, root should only be allowed to connect
  37. from
  38. 'localhost'. This ensures that someone cannot guess
  39. at
  40. the root password from the network.
  41. Disallow root login remotely? (Press y|Y for Yes,
  42. any other key for No) : y
  43. Success.
  44. By default, MySQL comes with a database named
  45. 'test' that
  46. anyone can access. This is also intended only for
  47. testing,
  48. and should be removed before moving into a
  49. production
  50. environment.
  51. Remove test database and access to it? (Press y|Y
  52. for Yes, any other key for No) : y
  53. - Dropping test database...
  54. Success.
  55. - Removing privileges on test database...
  56. Success.
  57. Reloading the privilege tables will ensure that all
  58. changes
  59. made so far will take effect immediately.
  60. Reload privilege tables now? (Press y|Y for Yes,
  61. any other key for No) : y
  62. Success.
  63. All done!
  64. [root@localhost mysql8]# mysql -uroot -p456
  65. mysql: [Warning] Using a password on the command
  66. line interface can be insecure.
  67. Welcome to the MySQL monitor. Commands end with ;
  68. or \g.
  69. Your MySQL connection id is 11
  70. Server version: 8.0.33 MySQL Community Server - GPL
  71. Copyright (c) 2000, 2023, Oracle and/or its
  72. affiliates.
  73. Oracle is a registered trademark of Oracle
  74. Corporation and/or its
  75. affiliates. Other names may be trademarks of their
  76. respective
  77. owners.
  78. Type 'help;' or '\h' for help. Type '\c' to clear
  79. the current input statement.
  80. mysql> quit
  81. Bye
  82. [root@localhost mysql8]#

二,安全用户角色权限

$PATH
搞系统设置设置⾥头path
⽬标包含mysql 可执⾏⽂件,那么就是由使⽤
在终端使⽤
./bin/mysql -h192.168.71.164 -P3306 -uroot -proot
1.远程登录前提条件是mysql.user表中的host属性为%,如果是
localhost就不允许远程登录,update mysql.user set host="%"
where user="root",flush privileges;
2.远程管理,可以使⽤图形化⼯具,sqlyog,navicat,掌握命令⼯
具,客户端⼯具 mysql
3.mysql -h192.168.71.129 -P3306 -uzhangmin -pZhang_min123
-h 主机 ip或者是域名 如果是localshost或者是127.0.0.1可省略
-P 端⼝ 默认是3306,如果是默认的,可以省略-u ⽤户名
-p 密码,可以不换⾏直接输⼊,也可以换⾏ 不回显输⼊密码
创建账户
  1. create user 'zhangmin'@'%' identified by
  2. 'Zhang_min123';
给权限
grant all on *.* to 'zhangmin'
创建库
create database if not exists test;
创建表
  1. use test;
  2. create table user(
  3. id int primary key,
  4. username varchar(45) not null,
  5. password varchar(45) not null
  6. );
添加数据
  1. insert into test.user values(1,"zhangsan","123");
  2. insert into test.user values(2,"lisi","456");
  3. insert into test.user values(3,"wamngwi","789");
  4. insert into test.user values(4,"zhaoliu","aaa");
添加lilaosi账号,修改密码,查看mysql.user中的lilaosi的信息
  1. mysql> create user 'lilaosi'@'%' identified by
  2. 'lilaoshi_123';
  3. ERROR 1819 (HY000): Your password does not satisfy
  4. the current policy requirements
  5. mysql> create user 'lilaosi'@'%' identified by
  6. 'Lilaoshi_123';
  7. Query OK, 0 rows affected (0.01 sec)
  8. mysql> alter user 'lilaosi'@'%' identified by
  9. 'Lilaosi_123';
  10. Query OK, 0 rows affected (0.01 sec)
  11. mysql> select host,user from mysql.user;
  12. +-----------+------------------+
  13. | host | user |
  14. +-----------+------------------+
  15. | % | lilaosi |
  16. | % | root |
  17. | % | zhangmin |
  18. | localhost | mysql.infoschema |
  19. | localhost | mysql.session |
  20. | localhost | mysql.sys |
  21. +-----------+------------------+
  22. 6 rows in set (0.00 sec)
使⽤root账号,为lilaosi账号添加test库存中所有的表的所有权限
  1. grant all on test.* to 'lilaosi';
  2. # lilaosi就获得了test库中所有的表的操作权限,但是,由于
  3. root没有个lilaosimysql库的权限,所以lilaosi账号⽆法查看
  4. mysql库

1.密码安全策略

查看密码策略

  1. mysql> show variables like 'validate%';
  2. +--------------------------------------+--------+
  3. | Variable_name | Value |
  4. +--------------------------------------+--------+
  5. | validate_password.check_user_name | ON |
  6. | validate_password.dictionary_file | |
  7. | validate_password.length | 8 |
  8. | validate_password.mixed_case_count | 1 |
  9. | validate_password.number_count | 1 |
  10. | validate_password.policy | MEDIUM |
  11. | validate_password.special_char_count | 1 |
  12. +--------------------------------------+--------+
  13. 7 rows in set (0.00 sec)
修改策略
  1. mysql> set global validate_password.length=0;
  2. mysql> set global validate_password.policy=LOW;
  3. mysql> show variables like 'validate%';
  4. +--------------------------------------+-------+
  5. | Variable_name | Value |
  6. +--------------------------------------+-------+
  7. | validate_password.check_user_name | ON |
  8. | validate_password.dictionary_file | |
  9. | validate_password.length | 4 |
  10. | validate_password.mixed_case_count | 0 |
  11. | validate_password.number_count | 0 |
  12. | validate_password.policy | LOW |
  13. | validate_password.special_char_count | 0 |
  14. +--------------------------------------+-------+

2.⽤户

创建⽤户
  1. 练习
  2. 创建三个账号,abc[abcd],ccc[a1b2c3] ,ddd[231343]
  3. <mysql> create user 'efg'@'%' identified by 'efg';
  4. ERROR 1819 (HY000): Your password does not satisfy
  5. the current policy requirements
  6. mysql> create user 'efgh'@'%' identified by 'efgh';
  7. Query OK, 0 rows affected (0.01 sec)
  8. mysql> select host,user from mysql.user;
  9. +-----------+------------------+
  10. | host | user |
  11. +-----------+------------------+
  12. | % | efgh |
  13. | % | root |
  14. | % | zhangmin |
  15. | localhost | mysql.infoschema |
  16. | localhost | mysql.session |
  17. | localhost | mysql.sys |
  18. | localhost | test1 |
  19. +-----------+------------------+
删除⽤户
  1. mysql> drop user 'zhangmin';
  2. Query OK, 0 rows affected (0.02 sec)
  3. mysql> select user from mysql.user;
  4. +------------------+
  5. | user |
  6. +------------------+
  7. | efgh |
  8. | root |
  9. | mysql.infoschema |
  10. | mysql.session |
  11. | mysql.sys |
  12. | test1 |
  13. +------------------+
  14. 6 rows in set (0.00 sec)
修改⽤户
  1. mysql> alter user 'zhangmin' identified by
  2. 'abc123';
  3. Query OK, 0 rows affected (0.01 sec)
练习
abc。ccc。ddd三个账号的密码修改为1234
查看⽤户

3.⻆⾊

创建⻆⾊
  1. mysql> create role 'a';
  2. Query OK, 0 rows affected (0.00 sec)
  3. mysql> show grants for 'a';
  4. +-------------------------------+
  5. | Grants for a@% |
  6. +-------------------------------+
  7. | GRANT USAGE ON *.* TO `a`@`%` |
  8. +-------------------------------+
  9. 1 row in set (0.00 sec)
  1. 练习
  2. 1.添加jingli⻆⾊
  3. create role 'jingli';
  4. 2.添加yuangong⻆⾊
  5. craete role 'yaungong';
  6. 3.为jingli添加select insert delete update权限
  7. grant select ,insert,delete,update on test.user to
  8. 'jingli';
  9. 4.为yuangong添加selectinsert权限
  10. grant select,insert on test.user to 'yuangong';
  11. 5.查看⻆⾊保存的表格
  12. selet host,user from mysql.user;
  13. 6.查看⻆⾊的权限
  14. show grants for 'jingli';
  15. show grants for 'yaungogng';
  16. 新增bbb和ccc两个⽤户bbb是经理需要增删改查权限,ccc是员⼯是
  17. 只需要新增和查看的权限
  18. grant jingli to ‘bbb’;
  19. grant yuangong to 'ccc';

4.权限

刷新权限
  1. mysql> flush privileges;
  2. Query OK, 0 rows affected (0.01 sec)
为root账号添加权限
  1. mysql> grant system_user on *.* to "root";
  2. mysql> show grants for 'root';
  3. +--------------------------------------------------
  4. ---------------------------------------------------
  5. ---------------------------------------------------
  6. ---------------------------------------------------
  7. ---------------------------------------------------
  8. ---------------------------------------------------
  9. ---------------------------------------------------
  10. ------------------------------+
  11. | Grants for root@%
  12. |
  13. +--------------------------------------------------
  14. ---------------------------------------------------
  15. ---------------------------------------------------
  16. ---------------------------------------------------
  17. ---------------------------------------------------
  18. ---------------------------------------------------
  19. ---------------------------------------------------
  20. ------------------------------+
  21. | GRANT SELECT, INSERT, UPDATE, DELETE, CREATE,
  22. DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES,
  23. INDEX, ALTER, SHOW DATABASES, SUPER, CREATE
  24. TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION
  25. SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW,
  26. CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT,
  27. TRIGGER, CREATE TABLESPACE, CREATE ROLE, DROP ROLE
  28. ON *.* TO `root`@`%` WITH GRANT OPTION |
  29. | GRANT SYSTEM_USER ON *.* TO `root`@`%`
  30. |
  31. +--------------------------------------------------
  32. ---------------------------------------------------
  33. ---------------------------------------------------
  34. ---------------------------------------------------
  35. ---------------------------------------------------
  36. ---------------------------------------------------
  37. ---------------------------------------------------
  38. ------------------------------+
  39. 2 rows in set (0.00 sec)
修改权限
  1. mysql> show grants for "efgh";
  2. +--------------------------------------------------
  3. -+
  4. | Grants for efgh@%
  5. |
  6. +--------------------------------------------------
  7. -+
  8. | GRANT SELECT, INSERT, DELETE ON *.* TO `efgh`@`%`
  9. |
  10. +--------------------------------------------------
  11. -+
  12. 1 row in set (0.00 sec)
  1. 练习步骤
  2. 1.添加aaa账户,设置密码aaaa
  3. drop user aaa;
  4. create user 'aaa'@'%' identified by 'aaaa';
  5. 2.使⽤aaa账户访问mysql服务
  6. mysql -h127.0.0.1 -P3306 -uaaa -paaaa
  7. 3.查看test数据库发现么有权限
  8. show databases;
  9. 4.退出并使⽤root账户登录
  10. quit|exit
  11. mysql -h127.0.0.1 -P3306 -uroot -proot0000
  12. 5.为aaa账户添加查看test.user表的权限
  13. grant select on test.user to 'aaa';
  14. 6.退出root,使⽤aaa账户登录
  15. quit|exit
  16. mysql -h127.0.0.1 -P3306 -uaaa -paaaa
  17. 7.查看数据库,查看表,查看表内容 能够正常查看
  18. show databases;
  19. user test;
  20. show tables;
  21. select * from user;
  22. 8.输⼊数据,没有权限
  23. insert into user values(5,"ermazi","ermazi");####
  24. 9.退出aaa使⽤root登录
  25. quit|exit
  26. mysql -h127.0.0.1 -P3306 -uroot -proot0000
  27. 10.为aaa添加insert权限
  28. grant insert on test.user to 'aaa';
  29. 11.退出root使⽤aaa登录
  30. exit|quit
  31. mysql -h127.0.0.1 -P3306 -uaaa -paaaa
  32. 12.向user表添加⼀⾏新的数据
  33. insert into test.user
  34. values(6,"zhangsanfeng","zhangsanfen");
  35. 13.修改user中⼀⾏的数据的password(密码)为111,没有
  36. update权限
  37. update test.user set password='zsf' where username-
  38. 'zhangsanfeng';
删除权限
  1. mysql> revoke all on *.* from "efgh";
  2. Query OK, 0 rows affected (0.00 sec)
  3. mysql> show grants for "efgh";
  4. +----------------------------------+
  5. | Grants for efgh@% |
  6. +----------------------------------+
  7. | GRANT USAGE ON *.* TO `efgh`@`%` |
  8. +----------------------------------+
  9. 1 row in set (0.00 sec)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/空白诗007/article/detail/936618
推荐阅读
相关标签
  

闽ICP备14008679号