找回密码
 注册
查看: 56|回复: 5

创建mysql用户并创建对应的访问库

[复制链接]

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
发表于 2024-7-23 15:43:31 | 显示全部楼层 |阅读模式
创建mysql用户并创建对应的访问库1 z4 ]  y2 N4 Y. L  q

8 p( _  {8 T: n1 q* l7 ?
0 x9 ^- ?$ v2 Y0 |! T: K% F2 FMariaDB [(none)]>  select distinct(User) from mysql.user;5 {1 r) e0 i% z: a
+-------------+
- j- w- |& F% w, n; e; q# r# E| User        |
/ N0 i) a6 j" d' l7 j7 ^( ?4 [+-------------+
9 h9 G1 \- G( Z) p7 a| mariadb.sys |) E1 Z# t" |" t1 o3 U
| mysql       |+ S' ?/ M* h5 x' {0 A' Y/ t+ ]# Y
| root        |9 X, j6 H9 [9 Q$ i: b; u
+-------------+5 ~4 d7 m  h- c6 T9 `, R' m
3 rows in set (0.003 sec)
+ I- V# [  t, L( J, P, K  Y5 I  ^! R1 t. ?
MariaDB [(none)]> create user victor@'%' identified by 'victzzzz';
- ~- b0 j- b$ h* BQuery OK, 0 rows affected (0.003 sec)
' Y9 ?( \! Y) [7 S8 Y8 c$ o2 Y& w* R5 ^+ _; d
MariaDB [(none)]> grant ALL PRIVILEGES on restflask.* to victor@'%' identified by 'victzzzz';
9 }7 X  K; g8 l, s; XQuery OK, 0 rows affected (0.001 sec)' O2 W! f% G6 a" ]- }
0 y# _4 f# }: a
MariaDB [(none)]> grant ALL PRIVILEGES on restflask.* to victor@'localhost' identified by 'victzzzz';
6 g" I  X' o& ?9 s4 Z) |6 aQuery OK, 0 rows affected (0.002 sec)" W/ ]6 `( C1 F6 A$ i

, s% r0 |3 }$ E! r7 E8 R* f" K
7 w% \" B# D+ ?- D9 R- H) w# S# |* S$ W
MariaDB [(none)]> create user victor@'%' identified by 'victxxxx;
  ~" b3 z; o; T% YQuery OK, 0 rows affected (0.003 sec)% k% P, v1 X3 ^+ g: x( [5 q* J

7 f( M& L& P( m5 m" xMariaDB [(none)]> create user victor@'localhost' identified by 'victxxxx';
1 `7 S0 l& K, J0 Y/ n  wQuery OK, 0 rows affected (0.001 sec)
8 j% q  P# u7 Z9 p7 m4 h5 o- }
9 Q9 h! V! d0 ]5 [5 f3 s) ~' b/ |2 f7 Y* Y* i3 _

4 N3 o/ C" z" l3 c* k$ y$ D7 {+ `3 W$ Z& D2 t# q/ b& S" M
7 W0 y8 T) L; E1 a& ^

3 y! `& b1 ]% D; c( w  B

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2024-7-23 15:44:09 | 显示全部楼层
MariaDB [(none)]> create database restflask ;
( e3 x+ ?& J2 ZQuery OK, 1 row affected (0.001 sec)
' d. t7 t! B  m+ z5 T6 c) {

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2024-7-23 16:00:24 | 显示全部楼层
测试连接 带ip地址访问:
& `( z# i% ]3 H0 T* t. ? mysql -u victor -p
( f3 \" D) p6 R. D6 A2 Z' q( y3 TEnter password:
$ b/ D% \" U  S" E" o& zWelcome to the MariaDB monitor.  Commands end with ; or \g.
, G* o1 M" l8 n! e8 S7 OYour MariaDB connection id is 16
" t8 j3 Y, H6 e+ a4 O) m& i8 KServer version: 10.5.22-MariaDB MariaDB Server* q( d! N" b7 a; Z
# F) T7 A- f0 b- A5 ]
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.1 v  \/ r2 |3 _. l- @. f2 G

) _% A7 H) b# zType 'help;' or '\h' for help. Type '\c' to clear the current input statement.' S0 f( Q- J1 R' F) j# G& S* W3 u
6 g+ X  [6 A% t6 A: H1 M
MariaDB [(none)]> show databases;! M4 x1 ?) u9 \
+--------------------+; G. x% O, c/ K. |. v
| Database           |# W# E) B- N" Y) s* @9 x
+--------------------+
3 R7 r5 |5 H+ j$ k' x8 Y. v- ?| information_schema |
$ L3 }, n) F5 N1 n8 _2 V& b  ?0 K| restflask          |
, {7 r3 _2 T) G  i' f' m: P+--------------------+( a* u' B- t1 {) I& X8 m/ t
2 rows in set (0.001 sec)2 L9 W# W/ ]1 x- m" j# Y( L
# N1 j4 C: l  v. z# q8 X  m# ?- l- e3 M
MariaDB [(none)]> use restflask
8 i5 a5 Y' P7 B- kDatabase changed  T3 E' q" @- W( W, C! j
MariaDB [restflask]> show tables;
& x' B0 I! w1 |Empty set (0.000 sec)
. x8 }9 C+ N  c: O4 L( z
0 q+ {, b8 c4 P' g# s8 PMariaDB [restflask]> exit+ w  y9 J; O" H5 s  X: o
Bye. t# b: W+ b6 d+ N, F: U/ y6 k
[root@python-flask mysqlclient-2.2.4]# mysql -u victor -p -h 192.168.13.131" G0 w9 ]( y7 z( T% O$ B
Enter password:
& l" l( o3 U4 i# d6 Q% D+ C2 vWelcome to the MariaDB monitor.  Commands end with ; or \g.
. x0 u6 m, P1 S3 RYour MariaDB connection id is 17
9 T6 o6 ~: R" G3 R5 gServer version: 10.5.22-MariaDB MariaDB Server, h$ ^, U* l) t. `1 A7 ^

1 M$ J3 g* M/ V3 G' HCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
4 p- ~5 R/ b" k; ?3 D  n, `/ G( C# h4 d  ~+ d% I
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
& Z+ L6 x8 O8 Y( w
& P' @9 g$ Z) uMariaDB [(none)]> exit9 Q( c1 j$ B/ ~% ^
Bye1 A4 ~" [6 Q4 d/ x% A

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2024-7-25 07:18:15 | 显示全部楼层
MariaDB [(none)]>  create user victor@'%' identified by 'xxxx';6 f9 E7 w% t( ?7 g( M( l) I* `& g
Query OK, 0 rows affected (0.004 sec)* d* ~1 r$ ]; ^5 c7 E

5 Q, d; t# k$ }. @7 }" _MariaDB [(none)]> grant ALL PRIVILEGES on testflask.* to victor@'%' identified by 'xxxx';
8 p1 E! `3 D1 c( d5 f* SQuery OK, 0 rows affected (0.001 sec)6 c! W/ H4 \* f) a5 C
3 X4 q/ u8 Q3 U9 E
MariaDB [(none)]> grant ALL PRIVILEGES on testflask.* to victor@'localhost' identified by 'xxxx';+ P2 J; p8 g& f8 E2 n, I
Query OK, 0 rows affected (0.002 sec)5 S* V$ Q+ Q, y: M/ e6 Y

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2024-7-27 00:12:19 | 显示全部楼层
MariaDB [(none)]> CREATE DATABASE `testflask` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci */ ;
  ~0 Z, l5 o+ b9 ^& V. P3 IQuery OK, 1 row affected (0.005 sec)$ P2 y! v7 x  a3 L& |# @

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2024-7-30 22:54:02 | 显示全部楼层
MariaDB [(none)]> show create database testflask- s+ P; O2 G, @0 i$ b
    -> ;5 Z  L4 ^: X5 I! i: C
+-----------+--------------------------------------------------------------------------------------------------+! h" f  w9 ]/ m* B
| Database  | Create Database                                                                                  |
. @7 S* n4 }5 h5 i+-----------+--------------------------------------------------------------------------------------------------+  a, p. s/ o, R& s4 r. K
| testflask | CREATE DATABASE `testflask` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci */ |
( U  d* Q! B0 V7 x' ~( ?6 Q% m+-----------+--------------------------------------------------------------------------------------------------+% L9 X9 B/ n5 l! \
1 row in set (0.001 sec)
; C+ A/ X- o" f0 o0 B9 [1 W0 d) {
您需要登录后才可以回帖 登录 | 注册

本版积分规则

返回首页|Archiver|手机版|小黑屋|易陆发现技术论坛 ( 蜀ICP备2026014127号-1 )

GMT+8, 2026-6-12 03:08 , Processed in 0.019030 second(s), 22 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表