赞
踩
[root@localhost ~]# ls -l /etc/my.cnf
-rw-r--r--. 1 root root 570 6月 8 2017 /etc/my.cnf
[root@localhost ~]# rm -rf /etc/my.cnf
[root@localhost ~]# yum -y remove mariadb
[root@localhost ~]# find / -name "*mysql*" -exec rm -rf {} \;
[root@localhost ~]# ls
mysql-8.0.33-linux-glibc2.12-x86_64.tar
[root@localhost ~]# tar -xvf mysql-8.0.33-linux-glibc2.12-x86_64.tar
[root@localhost ~]# tar -xf mysql-8.0.33-linux-glibc2.12-x86_64.tar.xz[root@localhost ~]# ls
[root@localhost ~]# cd mysql-8.0.33-linux-glibc2.12-x86_64/
[root@localhost mysql-8.0.33-linux-glibc2.12-x86_64]# ls[root@localhost mysql-8.0.33-linux-glibc2.12-x86_64]# vim support-files/mysql.server
[root@localhost ~]# cp -r mysql-8.0.33-linux-glibc2.12-x86_64/ /usr/local/mysql/
[root@localhost ~]# yum list installed | grep libaio
libaio.x86_64 0.3.109-13.el7 @anaconda
[root@localhost ~]# echo $?
0
[root@localhost ~]# useradd -r -s /sbin/nologin mysql
[root@localhost ~]# mkdir /usr/local/mysql/mysql-files
[root@localhost ~]# chown mysql:mysql /usr/local/mysql/mysql-files/
[root@localhost ~]# chmod 750 /usr/local/mysql/mysql-files/
[root@localhost ~]# ll /usr/local/mysql/
[root@localhost ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql
[root@localhost ~]# ls /usr/local/mysql/
[root@localhost ~]# /usr/local/mysql/bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data
[root@localhost ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql8
[root@localhost ~]# service mysql8 start
[root@mysql ~]# mysql -uabc -p123456
create user 'xiaojiang'@'%' identified by 'Zhang@2002';
eg:创建三个账号,abc[abcd] , ccc[a1b2c3] ,ddd[231343]
grant all on *.* to 'xiaojiang'
create database if not exists test;
use test;
create table user(
id int primary key,
username varchar(45) not null,
password varchar(45) not null
);
insert into test.user values(1,"zhangsan","123");
insert into test.user values(2,"lisi","456");
insert into test.user values(3,"wangwu","789");
insert into test.user values(4,"zhaoliu","aaa");
添加lilaosi账号,修改密码,查看mysql.user中的lilaosi的信息create user 'lilaosi'@'%' identified by 'lilaoshi_123';
alter user 'lilaosi'@'%' identified by 'Lilaosi_123';
select host,user from mysql.user;
使用root账号,为lilaosi账号添加test库存中所有的表的所有权限mysql -uroot -pZhang@2002
grant all on test.* to 'lilaosi';
#lilaosi就获得了test库中所有表的操作权限;但是由于root没有个lilaosimysql库的
权限,所以lilaosi账号无法查看mysql库
[root@mysql ~]# vim mysql.sh
mysql> show variables like 'validate%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password.check_user_name | ON |
| validate_password.dictionary_file | |
| validate_password.length | 8 |
| validate_password.mixed_case_count | 1 |
| validate_password.number_count | 1 |
| validate_password.policy | MEDIUM |
| validate_password.special_char_count | 1 |
+--------------------------------------+--------+
mysql>setglobal validate_password.length=0;
mysql>setglobal validate_password.policy=LOW;
mysql>showvariableslike'validate%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password.check_user_name | ON |
| validate_password.dictionary_file | |
| validate_password.length | 4 |
| validate_password.mixed_case_count | 0 |
| validate_password.number_count | 0 |
| validate_password.policy | LOW |
| validate_password.special_char_count | 0 |
+--------------------------------------+--------+
mysql>create user'efgh'@'%' identified by 'efgh';
Query OK,0 rows affected (0.01 sec)
mysql>select host,user from mysql.user;
+-----------+------------------+
| host |user |
+-----------+------------------+
|% | efgh |
|% | root |
|% | zhangmin |
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | test1 |
+-----------+------------------+
mysql>drop user'xiaojiang';
Query OK,0 rows affected (0.02 sec)
mysql>alter user'zhangmin' identified by 'abc123';
Query OK,0 rows affected (0.01 sec)
mysql>create role 'jingli';
Query OK,0 rows affected (0.00 sec)
mysql> select host,user from mysql.user;
ALTER ROLE 'role_name' [...属性...];
DROP ROLE 'role_name';
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> grant system_user on *.* to "root";
mysql> grant insert,delete,update,select on test.user to 'jingli';
mysql> show grants for "efgh";
+----------------------------------+
| Grants for efgh@% |
+----------------------------------+
| GRANT USAGE ON *.* TO `efgh`@`%` |
+----------------------------------+
1 row in set (0.00 sec)
mysql> show grants for 'bbb';
mysql>revoke all on*.* from "efgh";
Query OK,0 rows affected (0.00 sec)
1.添加aaa账户,设置密码aaaa
drop user aaa;
create user 'aaa'@'%' identified by 'aaaa';
2.使用aaa账户访问mysql服务
mysql -h127.0.0.1 -P3306 -uaaa -paaaa
3.查看test数据库发现么有权限
show databases;
4.退出并使用root账户登录
quit|exit
mysql -h127.0.0.1 -P3306 -uroot -proot0000
5.为aaa账户添加查看test.user表的权限
grant select on test.user to 'aaa';
6.退出root,使用aaa账户登录
quit|exit
mysql -h127.0.0.1 -P3306 -uaaa -paaaa
7.查看数据库,查看表,查看表内容 能够正常查看
show databases;
user test;
show tables;
select * from user;
8.输入数据,没有权限
insert into user values(5,"ermazi","ermazi");####
9.退出aaa使用root登录
quit|exit
mysql -h127.0.0.1 -P3306 -uroot -proot0000
10.为aaa添加insert权限
grant insert on test.user to 'aaa';
11.退出root使用aaa登录
exit|quit
mysql -h127.0.0.1 -P3306 -uaaa -paaaa
12.向user表添加一行新的数据
insert into test.user values(6,"zhangsanfeng","zhangsanfen");
13.修改user中一行的数据的password(密码)为111,没有update权限
update test.user set password='zsf' where username-'zhangsanfeng';
mysql> create role 'jingli';
Query OK, 0 rows affected (0.02 sec)
mysql> create role 'yuangong';
Query OK, 0 rows affected (0.02 sec)
#添加jingli,yuangong角色
mysql> grant insert,delete,update,select on test.user to 'jingli';
Query OK, 0 rows affected (0.00 sec)
#给jingli角色设置权限
mysql> show grants for 'jingli';
#查看jingli权限
+-----------------------------------------------------------------------+
| Grants for jingli@% |
+-----------------------------------------------------------------------+
| GRANT USAGE ON *.* TO `jingli`@`%` |
| GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.`user` TO `jingli`@`%` |
+-----------------------------------------------------------------------+
2 rows in set (0.00 sec)
mysql> grant select,insert on test.user to 'yuangong';
Query OK, 0 rows affected (0.01 sec)
mysql> show grants for 'yuangong';
+---------------------------------------------------------+
| Grants for yuangong@% |
+---------------------------------------------------------+
| GRANT USAGE ON *.* TO `yuangong`@`%` |
| GRANT SELECT, INSERT ON `test`.`user` TO `yuangong`@`%` |
+---------------------------------------------------------+
2 rows in set (0.00 sec)
mysql> select host,user from mysql.user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| % | aaa |
| % | efgh |
| % | jingli |
| % | xiaojiang |
| % | yuangong |
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+------------------+
9 rows in set (0.00 sec)
#新增bbb和ccc两个用户,bbb是经理需要增删改查权限,ccc是员工,只需要新增和查看的权限
mysql> create user 'bbb'@'%' identified by 'Zhang@2002';
Query OK, 0 rows affected (0.01 sec)
mysql> create user 'ccc'@'%' identified by 'Zhang@2002';
Query OK, 0 rows affected (0.01 sec)
mysql> grant jingli to 'bbb';
Query OK, 0 rows affected (0.01 sec)
mysql> grant yuangong to 'ccc';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> show grants for 'bbb';
+---------------------------------+
| Grants for bbb@% |
+---------------------------------+
| GRANT USAGE ON *.* TO `bbb`@`%` |
| GRANT `jingli`@`%` TO `bbb`@`%` |
+---------------------------------+
2 rows in set (0.00 sec)
mysql> show grants for 'ccc';
+-----------------------------------+
| Grants for ccc@% |
+-----------------------------------+
| GRANT USAGE ON *.* TO `ccc`@`%` |
| GRANT `yuangong`@`%` TO `ccc`@`%` |
+-----------------------------------+
2 rows in set (0.00 sec)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。