longxd

导航

 

Mysql是最流行的关系型数据库管理系统之一,由瑞典MySQL AB公司开发,目前属于Oracle公司。 MySQL是一种关联数据库管理系统,关联数据库将数据保存在不同的表中,而不是将所有数据放在一个大仓库内,这样就增加了速度并提高了灵活性。
(开源,免费)

#关系数据库,是建立在关系模型基础上的数据库,

现实世界中的各种实体以及实体之间的各种联系,均用关系模型来表示。

#关系模型 ,是指二维表格模型,因而一个关系型数据库就是由二维表及其之间的联系组成的一个数据组织。

# 实体:就是数据对象。


 库-->表-->数据


进入Mysql:(通常不使用root用户登录)

mysql -u用户名 –p密码
如:
#mysql -uroot -qwe123

创建用户:创建用户、赋予权限、查看用户信息……

 

pyvip@Vip:~$ mysql -uroot -pqwe123    #使用root用户进入mysql
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.21-0ubuntu0.16.04.1 (Ubuntu)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

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> select user();     #查看当前登录的用户
+----------------+
| user()         |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)


mysql> CREATE USER 'test'@'%' IDENTIFIED BY 'qwe123';   #创建用户
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL  ON *.* TO 'test'@'%';   #给用户赋予权限
Query OK, 0 rows affected (0.00 sec)

mysql> show grants for test;      #查看用户权限
+-------------------------------------------+
| Grants for test@%                         |
+-------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'test'@'%' |
+-------------------------------------------+
1 row in set (0.01 sec)

mysql> FLUSH PRIVILEGES;    #使更改立即生效
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT User FROM mysql.user;   #查看创建的用户 "test"
+------------------+
| User             |
+------------------+
| admin            |
| develop          |
| jianeng          |
| test             |
| xlong            |
| debian-sys-maint |
| mysql.session    |
| mysql.sys        |
| root             |
+------------------+
9 rows in set (0.00 sec)

mysql> drop user test@'%';     #删除用户
Query OK, 0 rows affected (0.01 sec)

mysql> SELECT User FROM mysql.user;     #查看test用户已经被删除
+------------------+
| User             |
+------------------+
| admin            |
| develop          |
| jianeng          |
| xlong            |
| debian-sys-maint |
| mysql.session    |
| mysql.sys        |
| root             |
+------------------+
8 rows in set (0.00 sec)

mysql> \q      #退出
Bye
pyvip@Vip:~$ ^C

 

 补充示例:

创建 nevermore 库:

Create database nevermore;

 

创建 admin 用户:

create user 'admin'@'172.168.%' identified by '23we@43we';                          # 172.168.%指允许172.168.0.0/16的网段机器可以连接。

GRANT all on nevermore.* to 'admin'@'172.168.%' with grant option;             # 配置权限,成为nevermore库的管理员。

flush privileges;

创建  readonly 用户:

create user 'readonly'@'%' identified by '4zRer23rew';      # %号类似通配符,指0.0.0.0/0网段都可以连接

grant select on nevermore.* to 'readonly'@'%';                  # 配置权限,只能只读nevermore数据库

flush privileges;

 

posted on 2018-04-14 11:25  longxd  阅读(157)  评论(0编辑  收藏  举报