mysql姓名_mysql基础

1. 关系型数据库介绍

1.1 数据结构模型

数据结构模型主要有:

层次模型

网状结构

关系模型

关系模型:

二维关系:row,column

数据库管理系统:DBMS

关系:Relational,RDBMS

1.2 RDBMS专业名词

常见的关系型数据库管理系统:

MySQL:MySQL,MariaDB,Percona-Server

PostgreSQL:简称为pgsql

Oracle

MSSQL

SQL:Structure Query Language,结构化查询语言

约束:constraint,向数据表提供的数据要遵守的限制

主键约束:一个或多个字段的组合,填入的数据必须能在本表中唯一标识本行。且必须提供数据,不能为空(NOT NULL)。

一个表只能存在一个

惟一键约束:一个或多个字段的组合,填入的数据必须能在本表中唯一标识本行。允许为空(NULL)

一个表可以存在多个

外键约束:一个表中的某字段可填入数据取决于另一个表的主键已有的数据

检查性约束

索引:将表中的一个或多个字段中的数据复制一份另存,并且这些数据需要按特定次序排序存储

1.3 关系型数据库的常见组件

关系型数据库的常见组件有:

数据库:database

表:table,由行(row)和列(column)组成

索引:index

视图:view

用户:user

权限:privilege

存储过程:procedure

存储函数:function

触发器:trigger

事件调度器:event scheduler

1.4 SQL语句

SQL语句有三种类型:

DDL:Data Defination Language,数据定义语言

DML:Data Manipulation Language,数据操纵语言

DCL:Data Control Language,数据控制语言

SQL语句类型对应操作

DDL

CREATE:创建

DROP:删除

ALTER:修改

DML

INSERT:向表中插入数据

DELETE:删除表中数据

UPDATE:更新表中数据

SELECT:查询表中数据

DCL

GRANT:授权

REVOKE:移除授权

2. mysql安装与配置

2.1 mysql安装

mysql安装方式有三种:

源代码:编译安装

二进制格式的程序包:展开至特定路径,并经过简单配置后即可使用

程序包管理器管理的程序包:

rpm:有两种

OS Vendor:操作系统发行商提供的

项目官方提供的

deb

安装mariadb,设置开机自启动并现在就启动。确保3306端口已经监听起来。

[root@test ~]# yum -y install mariadb*

[root@test ~]# systemctl enable --now mariadb

[root@test ~]# ss -antl

State Recv-Q Send-Q Local Address:Port Peer Address:Port

LISTEN 0 128 0.0.0.0:22 0.0.0.0:*

LISTEN 0 80 0.0.0.0:3306 0.0.0.0:*

LISTEN 0 128 [::]:22 [::]:*

给mysql设置登录密码为123

[root@win10 ~]# mysql -uroot -p

Enter password:

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection id is 8

Server version: 10.3.17-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> set password = password('123'); #后面的password是加密

Query OK, 0 rows affected (0.000 sec)

修改mysql登录密码

[root@test ~]# mysql -uroot -p123

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection id is 21

Server version: 10.3.17-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> alter user 'root'@'localhost' identified by '123456';

Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]> quit

Bye

[root@test ~]# mysql -uroot -p123456

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection id is 22

Server version: 10.3.17-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

mysql_secure_installation //安全初始化

[root@test ~]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB

SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current

password for the root user. If you've just installed MariaDB, and

you haven't set the root password yet, the password will be blank,

so you should just press enter here.

Enter current password for root (enter for none): 输入root账户的密码

Change the root password? [Y/n] y 是否改变root密码

New password:

Re-enter new password:

Password updated successfully!

Reloading privilege tables..

... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone

to log into MariaDB without having to have a user account created for

them. This is intended only for testing, and to make the installation

go a bit smoother. You should remove them before moving into a

production environment.

Remove anonymous users? [Y/n] y 要不要移除匿名账户

... Success!

Normally, root should only be allowed to connect from 'localhost'. This

ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n 要不要设置不允许root账户远程登陆

... skipping.

By default, MariaDB comes with a database named 'test' that anyone can

access. This is also intended only for testing, and should be removed

before moving into a production environment.

Remove test database and access to it? [Y/n] y 要不要移除测试数据库和访问它的权限

- Dropping test database...

... Success!

- Removing privileges on test database...

... Success!

Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

Reload privilege tables now? [Y/n] y 要不要重新加入权限表

... Success!

Cleaning up...

All done! If you've completed all of the above steps, your MariaDB

installation should now be secure.

Thanks for using MariaDB!

两种查看数据库的方法

[root@test ~]# mysql -uroot -p123123

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection id is 32

Server version: 10.3.17-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| performance_schema |

+--------------------+

3 rows in set (0.004 sec)

MariaDB [(none)]> quit

Bye

.................................................................

[root@test ~]# mysql -uroot -p123123 -e 'show databases;'

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| performance_schema |

+--------------------+

DDL操作

创建数据库

MariaDB [(none)]> CREATE DATABASE IF NOT EXISTS school;

Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> show databases;

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| performance_schema |

| school |

+--------------------+

4 rows in set (0.000 sec)

MariaDB [(none)]>

删除数据库

MariaDB [(none)]> DROP DATABASE IF EXISTS school;

Query OK, 0 rows affected (0.005 sec)

MariaDB [(none)]> show databases;

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| performance_schema |

+--------------------+

3 rows in set (0.000 sec)

MariaDB [(none)]>

表操作

创建一个空表

MariaDB [(none)]> CREATE DATABASE IF NOT EXISTS school;

Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> use school;

Database changed

MariaDB [school]> show tables;

Empty set (0.000 sec)

MariaDB [school]> CREATE TABLE student(id int not null,name varchar(50)null,age tinyint );

Query OK, 0 rows affected (0.004 sec)

MariaDB [school]> show tables;

+------------------+

| Tables_in_school |

+------------------+

| student |

+------------------+

1 row in set (0.000 sec)

MariaDB [school]>

查看表的结构

MariaDB [school]> DESC student;

+-------+-------------+------+-----+---------+-------+

| Field |Type | Null | Key |Default | Extra |

+-------+-------------+------+-----+---------+-------+

| id | int(11) | NO | | NULL | |

| name | varchar(50) | YES | | NULL | |

| age | tinyint(4) | YES | | NULL | |

+-------+-------------+------+-----+---------+-------+

3 rows in set (0.002 sec)

MariaDB [school]>

获取创建表的帮助

MariaDB [school]> help create table;

Name: 'CREATE TABLE'

Description:

Syntax:

CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name

(create_definition,...)

[table_options]

[partition_options]

Or:

CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name

[(create_definition,...)]

[table_options]

[partition_options]

select_statement

Or:

CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name

{ LIKE old_tbl_name | (LIKE old_tbl_name) }

create_definition:

col_name column_definition

| [CONSTRAINT [symbol]] PRIMARY KEY [index_type] (index_col_name,...)

[index_option] ...

| {INDEX|KEY} [index_name] [index_type] (index_col_name,...)

[index_option] ...

| [CONSTRAINT [symbol]] UNIQUE [INDEX|KEY]

[index_name] [index_type] (index_col_name,...)

[index_option] ...

| {FULLTEXT|SPATIAL} [INDEX|KEY] [index_name] (index_col_name,...)

[index_option] ...

| [CONSTRAINT [symbol]] FOREIGN KEY

[index_name] (index_col_name,...) reference_definition

| CHECK (expr)

column_definition:

data_type [NOT NULL | NULL] [DEFAULT default_value]

[AUTO_INCREMENT] [UNIQUE [KEY] | [PRIMARY] KEY]

[COMMENT 'string']

[COLUMN_FORMAT {FIXED|DYNAMIC|DEFAULT}]

[STORAGE {DISK|MEMORY|DEFAULT}]

[reference_definition]

...

...

...

修改表,加入班级class

MariaDB [school]> DESC student;

+-------+-------------+------+-----+---------+-------+

| Field |Type | Null | Key |Default | Extra |

+-------+-------------+------+-----+---------+-------+

| id | int(11) | NO | | NULL | |

| name | varchar(50) | YES | | NULL | |

| age | tinyint(4) | YES | | NULL | |

+-------+-------------+------+-----+---------+-------+

3 rows in set (0.001 sec)

MariaDB [school]> ALTER TABLE student ADD class varchar(20);

Query OK, 0 rows affected (0.004 sec)

Records: 0 Duplicates: 0 Warnings: 0

MariaDB [school]> desc student;

+-------+-------------+------+-----+---------+-------+

| Field |Type | Null | Key |Default | Extra |

+-------+-------------+------+-----+---------+-------+

| id | int(11) | NO | | NULL | |

| name | varchar(50) | YES | | NULL | |

| age | tinyint(4) | YES | | NULL | |

| class | varchar(20) | YES | | NULL | |

+-------+-------------+------+-----+---------+-------+

4 rows in set (0.002 sec)

删除age

MariaDB [school]> ALTER TABLE student DROP age;

Query OK, 0 rows affected (0.009 sec)

Records: 0 Duplicates: 0 Warnings: 0

MariaDB [school]> desc student;

+-------+-------------+------+-----+---------+-------+

| Field |Type | Null | Key |Default | Extra |

+-------+-------------+------+-----+---------+-------+

| id | int(11) | NO | | NULL | |

| name | varchar(50) | YES | | NULL | |

| class | varchar(20) | YES | | NULL | |

+-------+-------------+------+-----+---------+-------+

3 rows in set (0.001 sec)

MariaDB [school]>

删除表

MariaDB [school]> show tables;

+------------------+

| Tables_in_school |

+------------------+

| student |

+------------------+

1 row in set (0.000 sec)

MariaDB [school]> DROP TABLE student;

Query OK, 0 rows affected (0.003 sec)

MariaDB [school]> show tables;

Empty set (0.000 sec)

MariaDB [school]>

DML操作

DML操作包括增(INSERT)、删(DELETE)、改(UPDATE)、查(SELECT),均属针对表的操作。

MariaDB [school]> DESC student; 查看表的结构

+-------+-------------+------+-----+---------+-------+

| Field |Type | Null | Key |Default | Extra |

+-------+-------------+------+-----+---------+-------+

| id | int(11) | NO | | NULL | |

| name | varchar(50) | YES | | NULL | |

| age | tinyint(4) | YES | | NULL | |

+-------+-------------+------+-----+---------+-------+

3 rows in set (0.003 sec)

MariaDB [school]> ALTER TABLE student ADD class varchar(20);

Query OK, 0 rows affected (0.005 sec)

Records: 0 Duplicates: 0 Warnings: 0

MariaDB [school]> DESC student;

+-------+-------------+------+-----+---------+-------+

| Field |Type | Null | Key |Default | Extra |

+-------+-------------+------+-----+---------+-------+

| id | int(11) | NO | | NULL | |

| name | varchar(50) | YES | | NULL | |

| age | tinyint(4) | YES | | NULL | |

| class | varchar(20) | YES | | NULL | |

+-------+-------------+------+-----+---------+-------+

4 rows in set (0.001 sec)

增操作insert

MariaDB [school]> 在表里面加入数据

MariaDB [school]> INSERT INTO student (id,name,age,class) VALUE (1,'taochi',5,5),(2,'chensongling',20,6),(3,'wangming',21,5),(4,'fangxinxin',18,7);

Query OK, 4 rows affected (0.007 sec)

Records: 4 Duplicates: 0 Warnings: 0

SELECT语句

字段column表示法

表示符代表什么?

*

所有字段

as

字段别名,如col1 AS alias1

当表名很长时用别名代替

条件判断语句WHERE

操作类型常用操作符

操作符

>,=,<=,=,!=

BETWEEN column# AND column#

LIKE:模糊匹配

RLIKE:基于正则表达式进行模式匹配

IS NOT NULL:非空

IS NULL:空

条件逻辑操作

AND

OR

NOT

ORDER BY:排序,默认为升序(ASC)

ORDER BY语句意义

ORDER BY ‘column_name'

根据column_name进行升序排序

ORDER BY 'column_name' DESC

根据column_name进行降序排序

ORDER BY ’column_name' LIMIT 2

根据column_name进行升序排序

并只取前2个结果

ORDER BY ‘column_name' LIMIT 1,2

根据column_name进行升序排序

并且略过第1个结果取后面的2个结果

查操作select

查看表的内部数据

MariaDB [school]> SELECT * from student;

+----+--------------+------+-------+

| id | name | age | class |

+----+--------------+------+-------+

| 1 | taochi | 5 | 5 |

| 2 | chensongling | 20 | 6 |

| 3 | wangming | 21 | 5 |

| 4 | fangxinxin | 18 | 7 |

+----+--------------+------+-------+

4 rows in set (0.003 sec)

MariaDB [school]> SELECT name FROM student 查看name一列的数据

-> ;

+--------------+

| name |

+--------------+

| taochi |

| chensongling |

| wangming |

| fangxinxin |

+--------------+

4 rows in set (0.000 sec)

MariaDB [school]>

MariaDB [school]> SELECT class FROM student ORDER BY class;

+-------+

| class |

+-------+

| 5 |

| 5 |

| 6 |

| 7 |

+-------+

4 rows in set (0.004 sec)

MariaDB [school]> SELECT class FROM student ORDER BY class DESC;

+-------+

| class |

+-------+

| 7 |

| 6 |

| 5 |

| 5 |

+-------+

4 rows in set (0.000 sec)

MariaDB [school]> SELECT class FROM student ORDER BY class DESC limit 2;

+-------+

| class |

+-------+

| 7 |

| 6 |

+-------+

2 rows in set (0.000 sec)

MariaDB [school]> SELECT class FROM student ORDER BY class limit 2;

+-------+

| class |

+-------+

| 5 |

| 5 |

+-------+

2 rows in set (0.000 sec)

MariaDB [school]> SELECT class FROM student ORDER BY class limit 1,2;

ERROR 1327 (42000): Undeclared variable: 1,2

MariaDB [school]> SELECT class FROM student ORDER BY class limit 1 ,2;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ',2' at line 1

MariaDB [school]> SELECT class FROM student ORDER BY class limit 1,2

-> ;

+-------+

| class |

+-------+

| 5 |

| 6 |

+-------+

2 rows in set (0.000 sec)

MariaDB [school]> SELECT class FROM student ORDER BY class DESC limit 1,2;

+-------+

| class |

+-------+

| 6 |

| 5 |

+-------+

2 rows in set (0.000 sec)

MariaDB [school]> SELECT * FROM student WHERE age >=18

-> ;

+----+--------------+------+-------+

| id | name | age | class |

+----+--------------+------+-------+

| 2 | chensongling | 20 | 6 |

| 3 | wangming | 21 | 5 |

| 4 | fangxinxin | 18 | 7 |

+----+--------------+------+-------+

3 rows in set (0.004 sec)

MariaDB [school]> SELECT * FROM student WHERE age >=18 AND name = 'fangxinxin'

-> ;

+----+------------+------+-------+

| id | name | age | class |

+----+------------+------+-------+

| 4 | fangxinxin | 18 | 7 |

+----+------------+------+-------+

1 row in set (0.000 sec)

MariaDB [school]>

MariaDB [school]> INSERT INTO student (id,name,age,class) VALUE (5,'mufeng',21,8),(6,'leichen',20,9),(7,'yuqinghao',21,9);

Query OK, 3 rows affected (0.001 sec)

Records: 3 Duplicates: 0 Warnings: 0

MariaDB [school]> SELECT * FROM student;

+----+--------------+------+-------+

|id |name |age |class |

+----+--------------+------+-------+

|1 |taochi |5 |5 |

|2 |chensongling |20 |6 |

|3 |wangming |21 |5 |

|4 |fangxinxin |18 |7 |

|5 |mufeng |21 |8 |

|6 |leichen |20 |9 |

|7 |yuqinghao |21 |9 |

+----+--------------+------+-------+

7 rows in set (0.000 sec)

MariaDB [school]> SELECT * FROM student WHERE age BETWEEN 5 and 20;

+----+--------------+------+-------+

|id |name |age |class |

+----+--------------+------+-------+

|1 |taochi |5 |5 |

|2 |chensongling |20 |6 |

|4 |fangxinxin |18 |7 |

|6 |leichen |20 |9 |

+----+--------------+------+-------+

4 rows in set (0.004 sec)

MariaDB [school]>

MariaDB [school]> SELECT * FROM student WHERE age is not null;

+----+--------------+------+-------+

|id |name |age |class |

+----+--------------+------+-------+

|1 |taochi |5 |5 |

|2 |chensongling |20 |6 |

|3 |wangming |21 |5 |

|4 |fangxinxin |18 |7 |

|5 |mufeng |21 |8 |

|6 |leichen |20 |9 |

|7 |yuqinghao |21 |9 |

+----+--------------+------+-------+

7 rows in set (0.000 sec)

MariaDB [school]>

DML操作之改操作update

MariaDB [school]> SELECT * FROM student WHERE NAME = 'taochi';

+----+--------+------+-------+

| id | name | age | class |

+----+--------+------+-------+

| 1 | taochi | 5 | 5 |

+----+--------+------+-------+

1 row in set (0.000 sec)

MariaDB [school]> UPDATE student SET age = 30 WHERE name = 'taochi';

Query OK, 1 row affected (0.001 sec)

Rows matched: 1 Changed: 1 Warnings: 0

MariaDB [school]> SELECT * FROM student WHERE NAME = 'taochi';

+----+--------+------+-------+

| id | name | age | class |

+----+--------+------+-------+

| 1 | taochi | 30 | 5 |

+----+--------+------+-------+

1 row in set (0.000 sec)

MariaDB [school]>

删操作delete

MariaDB [school]> SELECT * FROM student;

+----+--------------+------+-------+

|id |name |age |class |

+----+--------------+------+-------+

|1 |taochi |30 |5 |

|2 |chensongling |20 |6 |

|3 |wangming |21 |5 |

|4 |fangxinxin |18 |7 |

|5 |mufeng |21 |8 |

|6 |leichen |20 |9 |

|7 |yuqinghao |21 |9 |

+----+--------------+------+-------+

7 rows in set (0.000 sec)

MariaDB [school]> DELETE FROM student WHERE id = 7;

Query OK, 1 row affected (0.001 sec)

MariaDB [school]> SELECT * FROM student;

+----+--------------+------+-------+

|id |name |age |class |

+----+--------------+------+-------+

|1 |taochi |30 |5 |

|2 |chensongling |20 |6 |

|3 |wangming |21 |5 |

|4 |fangxinxin |18 |7 |

|5 |mufeng |21 |8 |

|6 |leichen |20 |9 |

+----+--------------+------+-------+

6 rows in set (0.000 sec)

MariaDB [school]> DELETE FROM student;

Query OK, 6 rows affected (0.001 sec)

MariaDB [school]> SELECT * FROM student

-> ;

Empty set (0.000 sec)

MariaDB [school]>

truncate语句

truncate与delete的区别:

语句类型特点

delete

DELETE删除表内容时仅删除内容,但会保留表结构

DELETE语句每次删除一行,并在事务日志中为所删除的每行记录一项

可以通过回滚事务日志恢复数据

非常占用空间

truncate

删除表中所有数据,且无法恢复

表结构、约束和索引等保持不变,新添加的行计数值重置为初始值

执行速度比DELETE快,且使用的系统和事务日志资源少

通过释放存储表数据所用的数据页来删除数据,并且只在事务日志中记录页的释放

对于有外键约束引用的表,不能使用TRUNCATE TABLE删除数据

不能用于加入了索引视图的表

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

用户操作

MariaDB [(none)]> CREATE USER 'mei'@'127.0.0.1' IDENTIFIED BY 'mei123!'; 创建新的用户

Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> quit

Bye

[root@test ~]# mysql -umei -pmei123! -h127.0.0.1

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection id is 11

Server version: 10.3.17-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

~~~

删除用户

[root@test ~]# mysql -uroot -p123456

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection id is 12

Server version: 10.3.17-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> DROP USER 'mei'@'127.0.0.1';

Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]>

DCL操作

创建授权grant

权限类型(priv_type)

权限类型代表什么?

ALL

所有权限

SELECT

读取内容的权限

INSERT

插入内容的权限

UPDATE

更新内容的权限

DELETE

删除内容的权限

指定要操作的对象db_name.table_name

表示方式意义

*.*

所有库的所有表

db_name

指定库的所有表

db_name.table_name

指定库的指定表

WITH GRANT OPTION:被授权的用户可将自己的权限副本转赠给其他用户,说白点就是将自己的权限完全复制给另一个用户。不建议使用。

授权用户mei在所有位置上远程登录访问school数据库

MariaDB [(none)]> GRANT ALL ON *.* TO 'mei'@'%' IDENTIFIED BY 'mei123!';

Query OK, 0 rows affected (0.000 sec)

刷新

MariaDB [(none)]> flush privileges;

Query OK, 0 rows affected (0.001 sec) MariaDB [(none)]>

c8351a77dae3fad30b42ff0e9a4b8a8a.png

查看授权

MariaDB [(none)]> SHOW GRANTS;

+----------------------------------------------------------------------------------------------------------------------------------------+

| Grants for root@localhost |

+----------------------------------------------------------------------------------------------------------------------------------------+

| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9' WITH GRANT OPTION |

| GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION |

+----------------------------------------------------------------------------------------------------------------------------------------+

2 rows in set (0.000 sec)

指定用户查看授权

MariaDB [(none)]> SHOW GRANTS FOR mei;

+-------------------------------------------------------------------------------------------------------------+

| Grants for mei@% |

+-------------------------------------------------------------------------------------------------------------+

| GRANT ALL PRIVILEGES ON *.* TO 'mei'@'%' IDENTIFIED BY PASSWORD '*E8829D93984203BF9FF6D62CC391FED985B4B38B' |

+-------------------------------------------------------------------------------------------------------------+

1 row in set (0.000 sec)

MariaDB [(none)]>

取消授权REVOKE

MariaDB [(none)]> REVOKE ALL ON *.* FROM 'mei'@'%';

Query OK, 0 rows affected (0.001 sec)

注意:mysql服务进程启动时会读取mysql库中的所有授权表至内存中:

GRANT或REVOKE等执行权限操作会保存于表中,mysql的服务进程会自动重读授权表,并更新至内存中

对于不能够或不能及时重读授权表的命令,可手动让mysql的服务进程重读授权表

mysql> FLUSH PRIVILEGES;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值