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

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

[复制链接]

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
发表于 2024-7-23 15:43:31 | 显示全部楼层 |阅读模式
创建mysql用户并创建对应的访问库
  ~6 j6 a5 P( O# |/ `* {0 o
  y0 o7 M  S  E$ E, A: v- E
* s# p4 B- B/ X; IMariaDB [(none)]>  select distinct(User) from mysql.user;' s9 x% M9 \9 [
+-------------+
, H; W: x3 ?- f- l| User        |( p# J$ Q$ ]  U0 C
+-------------+
  [' I8 W, K  @" N* R! V| mariadb.sys |
4 d3 ^) }3 y& j1 t8 x| mysql       |# w" P) ^9 d- Y/ p- I5 g! o
| root        |: K! V, C! \6 q, p/ ?
+-------------+
) L* R5 t( N  T7 m6 x+ ~& z3 V3 rows in set (0.003 sec)
  J' ^" j* M( r' E7 B1 d$ G8 _6 C, K* Z) A0 v+ c, x! @+ ~5 ?
MariaDB [(none)]> create user victor@'%' identified by 'victzzzz';% _6 u3 K2 D0 q3 w! K
Query OK, 0 rows affected (0.003 sec)( [' U5 T/ P, ?# ?" H

* _! w' G/ Z$ lMariaDB [(none)]> grant ALL PRIVILEGES on restflask.* to victor@'%' identified by 'victzzzz';
! n1 K2 e( h) r% X- V- OQuery OK, 0 rows affected (0.001 sec)
# f% \2 D" {# Z* \( _+ {3 N) S/ z0 y
MariaDB [(none)]> grant ALL PRIVILEGES on restflask.* to victor@'localhost' identified by 'victzzzz';
. B) q& t' f8 L- R- w6 l! B. Z& F5 vQuery OK, 0 rows affected (0.002 sec), V  {0 E7 u2 m9 [( A7 n

; k& F+ \, R& w2 s& ~
7 m7 Y4 A2 Z! h4 W
3 {8 B3 K, C4 bMariaDB [(none)]> create user victor@'%' identified by 'victxxxx;
8 `& _) x% ~- I; fQuery OK, 0 rows affected (0.003 sec)
  q8 x+ a# D( t% {& O2 O0 g( O2 ?& Z# b2 C4 G
MariaDB [(none)]> create user victor@'localhost' identified by 'victxxxx';
) d1 v9 m( y, m( o" h7 sQuery OK, 0 rows affected (0.001 sec)
& K. v- {! B" ?) E- G5 O( n0 S; X) R! |

4 q* Q/ [) {/ Y4 F( ?/ s- q! p8 V7 ]" ]% j7 z, I

/ N5 ]% O8 B+ _
3 l0 E. t( ]0 z: X+ }  b7 q1 M5 t+ n  M

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2024-7-23 15:44:09 | 显示全部楼层
MariaDB [(none)]> create database restflask ;
; v8 K" J: c6 F9 N. o+ ]Query OK, 1 row affected (0.001 sec)/ Y3 C( p% ?' u

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2024-7-23 16:00:24 | 显示全部楼层
测试连接 带ip地址访问:
' D2 c' L! |2 K: | mysql -u victor -p. [4 n1 T/ |1 S$ _8 A! B9 f+ O  |
Enter password:
% v. P! ?( C. s, w$ CWelcome to the MariaDB monitor.  Commands end with ; or \g.
: Z/ b2 O1 M! d  @# Z4 X6 {Your MariaDB connection id is 16. k: q+ w) C/ m" W% ]& K
Server version: 10.5.22-MariaDB MariaDB Server) F: }' m+ x7 q  l( V: J

* m& ^9 W0 P3 xCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
0 G, H# W* f6 v4 B5 a: ]$ t  d& v
0 R* o+ F  g$ qType 'help;' or '\h' for help. Type '\c' to clear the current input statement.6 s: Q2 k/ [4 V+ X2 s5 C- \: {1 a
) h7 q8 Y7 y  w! L$ b- I
MariaDB [(none)]> show databases;
* {1 S6 L  v2 M% `5 j# o" J9 ?+--------------------+2 D- M5 C+ N  ?; R+ t) v- J
| Database           |; n# M( Y8 t1 _% z; B- L
+--------------------+
9 K9 G( ]$ O3 ^' w1 |3 ?| information_schema |$ ]: N# K! ~6 j: d0 s! Y4 I) s* M
| restflask          |8 v2 j7 l% A2 H" J
+--------------------+
9 V2 z" s9 R7 O# l1 C) _2 rows in set (0.001 sec)
1 i' s8 t$ t& [( M& E
9 ]- A4 E$ G2 d; J% g/ XMariaDB [(none)]> use restflask
+ s5 U7 ~" t8 [( |! p* MDatabase changed
8 @# E$ k3 g! \7 m3 i$ |2 QMariaDB [restflask]> show tables;" ?: O7 {* V6 ^) W' Z/ O: y1 n
Empty set (0.000 sec), p  e# F% M2 C7 g6 u
; i4 x1 J9 C7 h1 P" ^9 L% v9 v5 i" x
MariaDB [restflask]> exit
! r4 @. w% x, ]) J6 jBye
5 W- j5 z4 Z) u9 I9 t* s$ r( d/ }; K[root@python-flask mysqlclient-2.2.4]# mysql -u victor -p -h 192.168.13.131) O8 t1 p0 R+ ]9 Y2 j8 R7 @' \
Enter password:
! `" O2 y1 B( k* B/ W+ PWelcome to the MariaDB monitor.  Commands end with ; or \g.6 V9 R$ U1 I5 p, u" e+ k8 @0 P7 C
Your MariaDB connection id is 17
0 V; T. I# [* L8 }/ p8 a* |Server version: 10.5.22-MariaDB MariaDB Server
" e3 _! N. i$ U; d* o/ t! |  \% j* c
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
' w# w/ P( b, i7 ?5 e8 v/ s
. A7 `- w; s. y  A" HType 'help;' or '\h' for help. Type '\c' to clear the current input statement.
2 D  a" `( c, o; E, n/ L5 D* M* j+ \+ a: C! I% M$ q6 A
MariaDB [(none)]> exit
! M6 W# |: L+ P$ SBye( |/ o7 F- e# H/ l' F. ?

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2024-7-25 07:18:15 | 显示全部楼层
MariaDB [(none)]>  create user victor@'%' identified by 'xxxx';/ k$ ^+ }) R5 c8 i: z, Y
Query OK, 0 rows affected (0.004 sec)
2 M7 K! I6 t! P( t" z+ Q
1 X3 |% x; D: @0 c9 H9 PMariaDB [(none)]> grant ALL PRIVILEGES on testflask.* to victor@'%' identified by 'xxxx';
0 h) }" U8 {, u0 O9 R3 XQuery OK, 0 rows affected (0.001 sec)
) d+ _: o2 i/ d! n& k3 O% S
$ c" ^0 B, W8 o4 c/ a$ l8 r: VMariaDB [(none)]> grant ALL PRIVILEGES on testflask.* to victor@'localhost' identified by 'xxxx';6 ?+ X' P. S$ ]6 B" @
Query OK, 0 rows affected (0.002 sec), O& m$ h$ y# N" G

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 */ ;
$ e$ @. e0 ]" K, h- }. b2 kQuery OK, 1 row affected (0.005 sec)2 }! m8 D1 h; w0 W  r

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2024-7-30 22:54:02 | 显示全部楼层
MariaDB [(none)]> show create database testflask
4 X7 Q$ x$ m) K$ i  o, t    -> ;
- E" c- r6 F: P% @& h+-----------+--------------------------------------------------------------------------------------------------+, K- }* Y: e) V# d! E; u+ {9 h7 o
| Database  | Create Database                                                                                  |  ]$ S: V' t& @4 ^$ H9 m6 S
+-----------+--------------------------------------------------------------------------------------------------+' v  T0 S3 D% ]/ w
| testflask | CREATE DATABASE `testflask` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci */ |
+ `2 u- I1 e$ ~+ b+-----------+--------------------------------------------------------------------------------------------------+/ A* x) [7 s. N/ o  \3 b2 i' }
1 row in set (0.001 sec)* ^- ~; P9 s+ Y+ {: \
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-12 01:52 , Processed in 0.019480 second(s), 22 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

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