MySQL基操---⽤户密码与基本查看命令
⽤户部分
MySQL ⽤户设置
如果你需要添加 MySQL ⽤户,你只需要在 mysql 数据库中的 user 表添加新⽤户即可。
你可以在创建⽤户时,为⽤户指定权限,⽤户权限列表如下:
权限列表:
ALTER: 修改表和索引。
CREATE: 创建数据库和表。
DELETE: 删除表中已有的记录。
DROP: 抛弃(删除)数据库和表。
INDEX: 创建或抛弃索引。
葡萄酒的酿制方法INSERT: 向表中插⼊新⾏。
买新房要交哪些税REFERENCE: 未⽤。
SELECT: 检索表中的记录。
UPDATE: 修改现存表记录。
FILE: 读或写服务器上的⽂件。
PROCESS: 查看服务器中执⾏的线程信息或杀死线程。
RELOAD: 重载授权表或清空⽇志、主机缓存或表缓存。
SHUTDOWN: 关闭服务器。
ALL: 所有权限,ALL PRIVILEGES同义词。
USAGE: 特殊的 "⽆权限" 权限。
⽤ 户账户包括 "username" 和 "host" 两部分,后者表⽰该⽤户被允许从何地接⼊。tom@'%' 表⽰任何
地址,默认可以省略。还可以是"tom@192.168.1.%"、"tom@%.abc" 等。数据库格式为 db@table,可以是 "test.*" 或 "*.*",前者表⽰ test 数据库的所有表,后者表⽰所有数据库的所有表。
⼦句 "WITH GRANT OPTION" 表⽰该⽤户可以为其他⽤户分配权限。
以下为添加⽤户的的实例,⽤户名为test,密码为test123,并授权⽤户可进⾏ SELECT, INSERT 和 UPDATE操作权限:
⾸先进⼊表:
[root@localhost mysql]# mysql -u root -pEnter password: ******
mysql> use mysql;
Database changed
查看MySQL⾃带表中的⽤户信息:
mysql> select user,authentication_string,host from user;
+-----------+-------------------------------------------+-----------+
| user | authentication_string | host |
+-----------+-------------------------------------------+-----------+
| root | *6691484EA6B50DDDE1926A220DA01FA9E575C18A | localhost |
| mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost |
| root | *6691484EA6B50DDDE1926A220DA01FA9E575C18A | % |
+-----------+-------------------------------------------+-----------+
插⼊⽤户test:
mysql> grant select,insert,update,delete,create,drop
-> on tutorials.*
-> to 'test'@'localhost'
-> identified by 'test123';
Query OK, 0 rows affected, 1 warning (0.01 sec)
再次查看⽤户列表:
mysql> select user,authentication_string,host from user;
+-----------+-------------------------------------------+-----------+
| user | authentication_string | host |
+-----------+-------------------------------------------+-----------+
| root | *6691484EA6B50DDDE1926A220DA01FA9E575C18A | localhost |
| mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost | | root | *6691484EA6B50DDDE1926A220DA01FA9E575C18A | % |
| test | *676243218923905CF94CB52A3C9D3EB30CE8E20D | localhost |
+-----------+-------------------------------------------+-----------+
4 rows in set (0.00 sec)
删除test01⽤户:
mysql> select user,authentication_string,host from user;
唱片业+-----------+-------------------------------------------+-----------+
| user | authentication_string | host |
+-----------+-------------------------------------------+-----------+
| root | *6691484EA6B50DDDE1926A220DA01FA9E575C18A | localhost |
| mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost | | root | *6691484EA6B50DDDE1926A220DA01FA9E575C18A | % |
| test02 | *6691484EA6B50DDDE1926A220DA01FA9E575C18A | loaclhost |龙门石窟在哪
| test01 | *6691484EA6B50DDDE1926A220DA01FA9E575C18A | loaclhost |
+-----------+-------------------------------------------+-----------+
5 rows in set (0.00 sec)
mysql> drop user test01@loaclhost;
Query OK, 0 rows affected (0.00 sec)
mysql> select user,authentication_string,host from user;
+-----------+-------------------------------------------+-----------+
| user | authentication_string | host |
+-----------+-------------------------------------------+-----------+
| root | *6691484EA6B50DDDE1926A220DA01FA9E575C18A | localhost |
| mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost | | root | *6691484EA6B50DDDE1926A220DA01FA9E575C18A | % |
| test02 | *6691484EA6B50DDDE1926A220DA01FA9E575C18A | loaclhost |
+-----------+-------------------------------------------+-----------+
4 rows in set (0.00 sec)
重命名test02为test:
mysql> rename user 'test02'@'loaclhost' to 'test'@'192';
Query OK, 0 rows affected (0.00 sec)
mysql> select user,authentication_string,host from user;
+-----------+-------------------------------------------+-----------+
| user | authentication_string | host |
+-----------+-------------------------------------------+-----------+
| root | *6691484EA6B50DDDE1926A220DA01FA9E575C18A | localhost |
| mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost | | root | *6691484EA6B50DDDE1926A220DA01FA9E575C18A | % |
| test | *6691484EA6B50DDDE1926A220DA01FA9E575C18A | 192 |
+-----------+-------------------------------------------+-----------+
4 rows in set (0.00 sec)
撤销test⽤户update权限:
mysql> revoke update on *.* from 'test'@'192';
Query OK, 0 rows affected (0.01 sec)
MYSQL基本查看的操作
SHOW DATABASES:
列出 MySQL 数据库管理系统的数据库列表。
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
是老中医 mp34 rows in set (0.00 sec)
USE 数据库名 :
选择要操作的Mysql数据库,使⽤该命令后所有Mysql命令都只针对该数据库。
mysql> use sys;
Database changed
SHOW TABLES:
显⽰指定数据库的所有表,使⽤该命令前需要使⽤ use 命令来选择要操作的数据库。
mysql> show tables;
+----------------+
| Tables_in_mood |
+----------------+
| info |
+----------------+
1 row in set (0.00 sec)
SHOW COLUMNS FROM 数据表:
显⽰数据表的属性,属性类型,主键信息 ,是否为 NULL,默认值等其他信息。
mysql> show columns from info;
+-------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
内存卡格式化失败+-------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | char(10) | NO | | NULL | |
| score | decimal(5,2) | YES | | NULL | |
| hobby | int(2) | YES | | NULL | |
+-------+--------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)
SHOW INDEX FROM 数据表:
显⽰数据表的详细索引信息,包括PRIMARY KEY(主键)。
mysql> show index from info;
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_co mment |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| info | 0 | PRIMARY | 1 | id | A | 0 | NULL | NULL | | BTREE | | |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
1 row in set (0.00 sec)
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论