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

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

[复制链接]

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
发表于 2024-7-23 15:43:31 | 显示全部楼层 |阅读模式
创建mysql用户并创建对应的访问库  m& t" M. @$ `) J( l. v2 P
6 i( n% `' Y5 o( i) W

4 J1 Q2 o- g* ?  v* HMariaDB [(none)]>  select distinct(User) from mysql.user;: y# j& w: U* V2 d' ?( ?. \4 b/ S4 g
+-------------+2 z' r/ J4 F3 {- n+ [# n' d
| User        |" {: }6 U- P8 j
+-------------+
; W) O- [3 H- z: Z; w| mariadb.sys |: e& t4 p" R1 d6 _
| mysql       |7 P9 B' {( ~' y5 d
| root        |( e4 `) L7 ?: `9 w3 {3 K- v" F
+-------------+- S) [  H$ h$ {" _7 i/ B; i' v
3 rows in set (0.003 sec). D: B" J3 v6 R

6 J' I! q) }- O' u  x& rMariaDB [(none)]> create user victor@'%' identified by 'victzzzz';
/ _1 ~& F" g: p9 l; j' bQuery OK, 0 rows affected (0.003 sec)) n0 i) b. ~: a; e" M2 C* a

6 i# x8 [' u7 B: n  MMariaDB [(none)]> grant ALL PRIVILEGES on restflask.* to victor@'%' identified by 'victzzzz';" G9 E1 Q1 t5 q' Y  Y8 A# `
Query OK, 0 rows affected (0.001 sec)  P# |+ `2 W* Q: o/ o

: l- ~) m5 a% d5 mMariaDB [(none)]> grant ALL PRIVILEGES on restflask.* to victor@'localhost' identified by 'victzzzz';
. D2 I4 ^8 m2 L1 ZQuery OK, 0 rows affected (0.002 sec)" b: h5 _8 F( B4 x6 c3 x& y  ]
# N# l  Y6 c3 {( g; n6 f

2 Z+ {: u5 Q5 o' Y; Z" h, I5 n9 }/ D# U* `; m1 W" U" \: V1 r1 m
MariaDB [(none)]> create user victor@'%' identified by 'victxxxx;
1 R" J( {' t$ dQuery OK, 0 rows affected (0.003 sec)& z; D1 N! E; ]) y
: s$ U$ f6 p4 z* l. u# V: c; @
MariaDB [(none)]> create user victor@'localhost' identified by 'victxxxx';0 s, L3 y7 u$ F2 ]# k
Query OK, 0 rows affected (0.001 sec)! w+ M5 r$ v, [& H; @, R3 |

: |) g0 m. r3 g5 `1 j8 C& Q# Q) O; f" v# l
' |- t- t" Q1 Q2 K  e% Z
1 f' v8 E7 c5 S; w# U; w$ h: R9 j

' E; c- ^7 c! r3 q7 g' f& h
  b; F  ]4 e- m* G9 G

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2024-7-23 15:44:09 | 显示全部楼层
MariaDB [(none)]> create database restflask ;
  d& h7 o2 `' O: c/ @4 t( Y* zQuery OK, 1 row affected (0.001 sec)
2 o" w6 s8 e- i0 v7 j

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2024-7-23 16:00:24 | 显示全部楼层
测试连接 带ip地址访问:# u! L2 C1 [' e
mysql -u victor -p
' W% {1 Z% o# G. s# t1 DEnter password:
# C. b# L5 [! IWelcome to the MariaDB monitor.  Commands end with ; or \g.
. T9 q3 R" m' X! f6 g; [( vYour MariaDB connection id is 16
3 U0 v' O: B6 h% Y) s, tServer version: 10.5.22-MariaDB MariaDB Server, R8 s. v4 L, G6 s. I7 {& O( x5 K

$ v, g1 @. g( h. C" A: ZCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.( B. b9 z9 M" l6 X) R
. g4 T2 y7 m) b  S0 q* d) b0 u1 c
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.2 E2 K3 {8 D$ D) ]
( X: G& ?; O8 F9 Q
MariaDB [(none)]> show databases;  e0 F! Q6 @- {5 e# e/ N
+--------------------+& _9 A( w2 q# L* \
| Database           |
3 `5 ~" I0 g6 e; m* o0 O- C+--------------------+
# w! T0 Z! f$ d| information_schema |2 U, g; V5 ?; w2 ]% t0 c0 b
| restflask          |
8 {/ C" ^' m% {# K+--------------------+
+ X$ G* g  U: I' H! J2 rows in set (0.001 sec); ^) q, n$ e& T; X/ [* z

; @6 c* Y. q$ [7 wMariaDB [(none)]> use restflask
0 E+ C9 u# c8 T: `: G% o5 H1 lDatabase changed
# O  x4 @+ E  EMariaDB [restflask]> show tables;
" h0 M6 _# R+ \+ u$ ~Empty set (0.000 sec)
* b- V- N6 k& L; I* U: S' ?* A% D* y) |" i: v; n4 h8 ~( _
MariaDB [restflask]> exit
: E0 E: U- j; b1 {" PBye
/ J: X, U  v: C% w  T! u2 M! N[root@python-flask mysqlclient-2.2.4]# mysql -u victor -p -h 192.168.13.1315 Z- C) D2 u4 p) n3 X, L
Enter password:
  S, j7 w3 J! l4 Y: P" f) j* N+ tWelcome to the MariaDB monitor.  Commands end with ; or \g.
  I3 n# z0 g" f8 S, I8 c7 ZYour MariaDB connection id is 176 \! w, M% O3 A9 q" `" I. g
Server version: 10.5.22-MariaDB MariaDB Server4 y. B* t8 v! v8 B6 R' H3 R  m" Q
, |  I! |. g/ v! |
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.$ ]! [, E% [  v% M  u' d
6 \) v$ a$ O! ?' K% ^. I6 w
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
5 r  C  O+ j+ F/ n4 S2 e: ]/ J% I4 _. ~! u! y
MariaDB [(none)]> exit+ }# \5 E+ ^. Z! A$ q  k0 b7 E( O
Bye
/ {- J5 Q; S! ^' q

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2024-7-25 07:18:15 | 显示全部楼层
MariaDB [(none)]>  create user victor@'%' identified by 'xxxx';3 ]8 P  v% a9 S9 c# K
Query OK, 0 rows affected (0.004 sec)2 Z4 O+ h# U" `" A
" q4 w* x7 T: A( C3 x1 {/ V3 U
MariaDB [(none)]> grant ALL PRIVILEGES on testflask.* to victor@'%' identified by 'xxxx';
5 h) ]8 o  ^  S: V1 |  MQuery OK, 0 rows affected (0.001 sec)3 a5 d  |7 B3 }# K6 c8 o2 d

8 r6 w; O( P# |: z- b) N* TMariaDB [(none)]> grant ALL PRIVILEGES on testflask.* to victor@'localhost' identified by 'xxxx';
) ]" D: |, ]) C/ \0 A5 B: BQuery OK, 0 rows affected (0.002 sec)9 ~1 ?( W( n: x! N$ J

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 */ ;# T, s9 i7 d5 C1 c9 y  Q
Query OK, 1 row affected (0.005 sec)5 B8 Q. V4 b- @: e0 D1 _7 z

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2024-7-30 22:54:02 | 显示全部楼层
MariaDB [(none)]> show create database testflask
# }+ S/ V1 g0 p. J1 j0 b6 w( `    -> ;
4 u" T0 E7 j  u% ~  S6 d4 i% ]% u/ r9 o: N+-----------+--------------------------------------------------------------------------------------------------+# }# }* S" O$ d; X
| Database  | Create Database                                                                                  |0 J. O. T( @2 o; ^* n, L$ L
+-----------+--------------------------------------------------------------------------------------------------+  J+ E' p1 }) V9 u5 j
| testflask | CREATE DATABASE `testflask` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci */ |
2 a3 \! N' M! f  `+-----------+--------------------------------------------------------------------------------------------------+
1 I* A; S* H1 J$ B$ o1 row in set (0.001 sec)
4 p8 U2 ~/ P: U+ t4 E5 Q: x
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-12 01:10 , Processed in 0.240185 second(s), 21 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

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