公司网站突然打不开了,淘宝返利网站怎么做的,中国建设教育协会官网证书查询,免费h5页面制作软件数据库用户管理
1.创建用户
MySQL在安装是#xff0c;会默认创建一个名位root的用户#xff0c;该用户拥有超级权限#xff0c;可以控制整个MySQL服务器。
在对MySQL的日常管理和操作中#xff0c;通常创建一些具有适当权限的用户#xff0c;尽可能的不用或少用root登录…数据库用户管理
1.创建用户
MySQL在安装是会默认创建一个名位root的用户该用户拥有超级权限可以控制整个MySQL服务器。
在对MySQL的日常管理和操作中通常创建一些具有适当权限的用户尽可能的不用或少用root登录系统以此来确保数据的安全访问。
可以使用create use语句创建用户并设置相应密码
create user 用户 [indentified by [password] password]参数说明
用户
指定创建用户账号格式为 user_name’host_name。这里的user_name是用户名host_name为主机名即用户连接 MySQL 时所用主机的名字。如果在创建的过程中只给出了用户名而没
指定主机名那么主机名默认为“%”表示一组主机即对所有主机开放权限。
IDENTIFIED BY子句
用于指定用户密码。新用户可以没有初始密码若该用户不设密码可省略此子句。
PASSWORD ‘password’
PASSWORD 表示使用哈希值设置密码该参数可选。如果密码是一个普通的字符串则不需要使用 PASSWORD 关键字。‘password’ 表示用户登录时使用的密码需要用单引号括起来。
⚠️使用 CREATE USER 语句时应注意以下几点 CREATE USER 语句可以不指定初始密码。但是从安全的角度来说不推荐这种做法。 使用 CREATE USER 语句必须拥有 mysql 数据库的 INSERT 权限或全局 CREATE USER 权限。 使用 CREATE USER 语句创建一个用户后MySQL 会在 mysql 数据库的 user 表中添加一条新记录。 CREATE USER 语句可以同时创建多个用户多个用户用逗号隔开。
新创建的用户拥有的权限很少它们只能执行不需要权限的操作。如登录 MySQL、使用 SHOW 语句查询所有存储引擎和字符集的列表等。如果两个用户的用户名相同但主机名不同MySQL 会将它们视为两个用户并允许为这两个用户分配不同的权限集合。
案例1
创建一个用户用户名是test1密码是test1主机名是localhost。 mysql create user test1locahost identified by test1;
Query OK, 0 rows affected (0.01 sec)mysql select user ,host from mysql.user;
-----------------------------
| user | host |
-----------------------------
| test1 | locahost |
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
-----------------------------
5 rows in set (0.00 sec)C:\Users\kmysql -utest1 -p
Enter password: *****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.4.3 MySQL Community Server - GPL
Copyright (c) 2000, 2024, 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 show databases;
--------------------
| Database |
--------------------
| information_schema |
| performance_schema |
--------------------
2 rows in set (0.01 sec)2.用户修改
可以使用rename user语句修改一个或多个已经存在的用户账号。
rename user 旧用户 to 新用户旧用户系统中已经存在的 MySQL 用户账号。
新用户新的 MySQL 用户账号。
使用 RENAME USER 语句时应注意以下几点 RENAME USER 语句用于对原有的 MySQL 用户进行重命名。 若系统中旧账户不存在或者新账户已存在该语句执行时会出现错误。 使用 RENAME USER 语句必须拥有 mysql 数据库的 UPDATE 权限或全局 CREATE USER 权限。
案例
将用户test1修改为testuser1主机是locahost mysql RENAME USER test1localhost TO testuser1localhost;
Query OK, 0 rows affected (0.01 sec)mysql select user,host from mysql.user;
-----------------------------
| user | host |
-----------------------------
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
| testuser1 | localhost |
-----------------------------
5 rows in set (0.00 sec)C:\Users\kittodmysql -utestUser1 -p
Enter password: *****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 22
Server version: 8.4.3 MySQL Community Server - GPL
Copyright (c) 2000, 2024, 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
statement3.用户授权
可以通过mysql.user表中的数据记录来查看相应的用户权限也可以使用show grants语句来查询用户的权限。
mysql数据库下的user表中存储这用户的基本权限也可以使用select语句来查看。
select * from mysql.user;要执行该语句就必须拥有对user表的查询权限。
⚠️新创建的用户只有登录mysql服务器的权限没有任何其他权限不能查询user表。
除了使用select语句之外还可以使用show grants for语句查看权限
show grants for usernamehostname;案例1 mysql show grants for testuser1localhost;
-----------------------------------------------
| Grants for testuser1localhost |
-----------------------------------------------
| GRANT USAGE ON *.* TO testuser1localhost |
-----------------------------------------------
1 row in set (0.00 sec)
其中USAGE ON *.*表示该用户对任何数据库和任何表都没有权限。
授权就是为某个用户赋予某些权限。例如可以为新建的用户赋予查询所有数据库和表的权限。MySQL提供了 GRANT 语句来为用户设置权限。
案例2 mysql grant all on test.* to testuser1localhost;
Query OK, 0 rows affected (0.01 sec)mysql show grants for testuser1localhost;
-------------------------------------------------------------
| Grants for testuser1localhost |
-------------------------------------------------------------
| GRANT USAGE ON *.* TO testuser1localhost |
| GRANT ALL PRIVILEGES ON test.* TO testuser1localhost |
-------------------------------------------------------------
2 rows in set (0.00 sec)# 使用用户 testUser1
mysql show databases;
--------------------
| Database |
--------------------
| information_schema |
| performance_schema |
| test |
--------------------
3 rows in set (0.00 sec)
mysql use test;
Database changed
mysql show tables;
----------------
| Tables_in_test |
----------------
| dept |
| emp |
| like_tb_emp1 |
| myview |
| salgrade |
| tb_dept1 |
| tb_dept2 |
| tb_dept3 |
| tb_dept4 |
| tb_emp1 |
| tb_emp4 |
| tb_emp5 |
| tb_emp6 |
----------------
13 rows in set (0.00 sec)案例3
mysql revoke all on test.* from testuser1localhost;
Query OK, 0 rows affected (0.01 sec)mysql show grants for testuser1localhost;
-----------------------------------------------
| Grants for testuser1localhost |
-----------------------------------------------
| GRANT USAGE ON *.* TO testuser1localhost |
-----------------------------------------------
1 row in set (0.00 sec)### 使用用户 testUser1
mysql show databases;
--------------------
| Database |
--------------------
| information_schema |
| performance_schema |
--------------------
2 rows in set (0.00 sec)4.删除用户
使用drop use语句来删除用户也可以直接在mysql.user表中删除用户以及相关权限。
drop user 用户其中用户用来指定需要删除的用户账号。
案例 mysql drop user testuser1localhost;
Query OK, 0 rows affected (0.01 sec)mysql show grants for testuser1localhost;
ERROR 1141 (42000): There is no such grant defined for user testuser1 on host localhost