授权完成后,切换到heima用户,再次查看数据库就可以看到刚才授权的mysql数据库了,并且可以操作mysql数据库中user表的内容
MariaDB [(none)]> show databases;+--------------------+| Database|+--------------------+| information_schema || mysql|+--------------------+2 rows in set (0.01 sec)MariaDB [(none)]> use mysql;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedMariaDB [mysql]> show tables;+-----------------+| Tables_in_mysql |+-----------------+| user|+-----------------+1 row in set (0.00 sec)MariaDB [mysql]> select host,user,password from user where user='heima';+-----------+-------+-------------------------------------------+| host| user| password|+-----------+-------+-------------------------------------------+| localhost | heima | *58613E96F5518C264EA39AA2A57D3DFEB191E343 |+-----------+-------+-------------------------------------------+1 row in set (0.00 sec)MariaDB [mysql]> exitBye[root@mariadb ~]#
3.2.2 移除账户权限当员工离职或其他原因需要移除账户权限时,可以使用root管理员登录,通过revoke语句进行移除
MariaDB [(none)]> revoke select,update,delete,insert on mysql.user from heima@localhost;Query OK, 0 rows affected (0.00 sec)MariaDB [(none)]> show grants for heima@localhost;+------------+| Grants for heima@localhost|+------------+| GRANT USAGE ON *.* TO 'heima'@'localhost' IDENTIFIED BY PASSWORD '*58613E96F5518C264EA39AA2A57D3DFEB191E343' |+-------------+1 row in set (0.00 sec)MariaDB [(none)]> exit
四、MariaDB数据库和表管理4.0 知识储备简单列举几个最基础的命令
- 创建数据库
- 描述表
- 更新表单中的数据
- 指定使用的数据库
- 显示当前已有的数据库
- 显示当前数据库中的表
- 从表单中选中某个记录值
- 从表单中删除某个记录值
4.1 创建数据库创建一个名为 heima的数据库
MariaDB [(none)]> create database heima;Query OK, 1 row affected (0.00 sec)MariaDB [(none)]> show databases;+--------------------+| Database|+--------------------+| information_schema || heima|| mysql|| performance_schema |+--------------------+4 rows in set (0.00 sec)MariaDB [(none)]>
4.2 创建数据库表切换到刚才创建的heima数据库,在其中创建user表,包含姓名和年龄两个字段MariaDB [(none)]> use heimaDatabase changedMariaDB [heima]> create table user(name char(15),age int);Query OK, 0 rows affected (0.01 sec)MariaDB [heima]> show tables;+-----------------+| Tables_in_heima |+-----------------+| user|+-----------------+1 row in set (0.00 sec)MariaDB [heima]> describe user;+-------+----------+------+-----+---------+-------+| Field | Type| Null | Key | Default | Extra |+-------+----------+------+-----+---------+-------+| name| char(15) | YES|| NULL||| age| int(11)| YES|| NULL||+-------+----------+------+-----+---------+-------+2 rows in set (0.00 sec)MariaDB [heima]>
五、MariaDB表数据管理数据库表中数据的查找分为CRUD,也就是通常所说的增、删、改、查 。5.1 添加数据使用insert into语句向heima数据库的user表中插入数据
MariaDB [heima]> insert into user(name,age) values('heima',18);Query OK, 1 row affected (0.00 sec)MariaDB [heima]> select * from user;+-------+------+| name| age|+-------+------+| heima |18 |+-------+------+1 row in set (0.00 sec)MariaDB [heima]>
5.2 查询数据查询使用select语句,并可以结合where、group by、order by等语句进行综合查询 。在user表插入一条数据,然后根据年龄查询小于1岁的用户
MariaDB [heima]> insert into user(name,age) values("leo",1);Query OK, 1 row affected (0.00 sec)MariaDB [heima]> select * from user where age<2;+------+------+| name | age|+------+------+| leo|1 |+------+------+1 row in set (0.00 sec)MariaDB [heima]>
5.3 修改数据修改数据使用update语句,在user表中将heima用户的年龄修改为19岁MariaDB [heima]> update user set age=19 where name='heima';Query OK, 1 row affected (0.00 sec)Rows matched: 1Changed: 1Warnings: 0MariaDB [heima]> select * from user;+-------+------+| name| age|+-------+------+| heima |19 |+-------+------+1 row in set (0.00 sec)MariaDB [heima]>
5.4 删除数据删除数据使用delete语句,以下分别演示,删除用户名为leo的用户和删除所有用户
推荐阅读
- python3快速爬取房源信息,并存入mysql数据库,超详细
- MySQL 全文索引实现一个简单版搜索引擎
- 一分钟搞懂;如何通过nginx将网站访问改为https
- utf8字符集下的比较规则
- CentOS下MySQL8.0的超详细的安装及配置文档
- MySQL/数据库 知识点总结
- mysql数据库备份及其恢复
- 在线yum安装 Linux中安装MySQL数据库下
- 玩转Docker:十分钟搞定MySQL的安装
- 三分钟学会如何找回mysql密码