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

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

[复制链接]

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
发表于 2024-7-23 15:43:31 | 显示全部楼层 |阅读模式
创建mysql用户并创建对应的访问库7 L& B8 h6 z4 V0 B+ }; T

. a4 n# [4 ~; d5 H$ t0 D, [4 `/ ?7 N; |' f4 X! R
MariaDB [(none)]>  select distinct(User) from mysql.user;
. Z+ P) H' A6 @/ F1 G+-------------+( k9 n2 B  j5 m) Z$ {
| User        |
7 g8 z. f7 |2 ?" ^" H+-------------+% C7 G! r" _! j; _
| mariadb.sys |
( ~7 r: {4 M( U2 e/ _' L; D0 v: J| mysql       |
* g" u- r* B! q! D. R( {7 u0 f. J| root        |+ m, x& P3 d2 d7 B) W0 |5 g) O, Z0 {
+-------------+" c! T. R* M. S' f& ?
3 rows in set (0.003 sec)1 t7 `2 M( C, n1 E" ^5 B
/ |3 U4 z  U0 O
MariaDB [(none)]> create user victor@'%' identified by 'victzzzz';
3 \8 j( c2 c6 n' |3 {3 a9 q0 PQuery OK, 0 rows affected (0.003 sec)7 \, m3 L! R; e  i, L7 [

+ }/ r) X5 `( oMariaDB [(none)]> grant ALL PRIVILEGES on restflask.* to victor@'%' identified by 'victzzzz';
; }% Z5 y1 ~- s/ S+ @- c3 S( ZQuery OK, 0 rows affected (0.001 sec)
( V0 M* I- y7 F" ~- v  O/ v5 y4 N, E
MariaDB [(none)]> grant ALL PRIVILEGES on restflask.* to victor@'localhost' identified by 'victzzzz';
) _; j  a8 |' [- o8 eQuery OK, 0 rows affected (0.002 sec)
, h  T# `) z* j3 I" y/ p' U  U
2 B6 d  p- i+ r2 [4 M/ x$ n* p0 `" l6 _' T6 M& S# [

( @9 u9 `+ {- Q9 dMariaDB [(none)]> create user victor@'%' identified by 'victxxxx;
: W5 z+ ^9 g# N7 ?, HQuery OK, 0 rows affected (0.003 sec)7 [( n, ^" P9 b9 V( I2 E, z2 k

2 m( [4 o& I, q) wMariaDB [(none)]> create user victor@'localhost' identified by 'victxxxx';
9 E6 B$ w& r' }/ bQuery OK, 0 rows affected (0.001 sec)
6 ~& c' r  c; G4 _2 t- P. v  n. b4 Y
8 q9 U" c# g4 D2 j* @+ k7 z$ Y. c$ |2 `* o

) O& I$ p$ M" l$ |& P& C3 J* n7 r, y, P+ M! Q

7 U4 z* g; d' F: |0 r  y: C2 r. B" L

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2024-7-23 15:44:09 | 显示全部楼层
MariaDB [(none)]> create database restflask ;, W% ?3 o* Y3 w: q
Query OK, 1 row affected (0.001 sec)% n% J6 L% h5 n8 s6 H4 T

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2024-7-23 16:00:24 | 显示全部楼层
测试连接 带ip地址访问:
. p  ]/ p$ R; n* o* h mysql -u victor -p
8 t5 \* L* f6 e% u  B) j; \; x. HEnter password:
8 {1 B) y2 ?% g( q1 J7 ^  [7 SWelcome to the MariaDB monitor.  Commands end with ; or \g.
6 y8 F2 u3 m6 @5 `. N- s" `, s% EYour MariaDB connection id is 16
$ P" n1 |; i# {4 i3 j, ]4 K2 Z' N2 SServer version: 10.5.22-MariaDB MariaDB Server) r% b2 n5 t8 v; A
1 f6 d2 h3 P! E8 n3 A
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
, t5 s- i8 |, i7 `" z! b1 M! J
& {. r1 ~; }  }6 N6 qType 'help;' or '\h' for help. Type '\c' to clear the current input statement.
, V- o% S! F% x: `: `6 O  K  s  Y; B) T/ C: j; t" Y
MariaDB [(none)]> show databases;
7 P* w& E+ v, S$ x, y* U7 Z+--------------------+& l5 S1 Z! ~6 b
| Database           |
) w$ ^' ^1 m' ^& \* I+--------------------+! y6 u  ~9 Z5 M/ e  E  W8 Q- O
| information_schema |
* g/ b2 i; d3 k5 @4 J| restflask          |
6 o6 [4 _- }6 v, t' o4 ~& p7 n+--------------------+  j4 R% P( D2 U; F: P
2 rows in set (0.001 sec)
  h: e/ V$ l7 @  Y3 Y3 a$ o1 i( @- {; @/ S1 n" C- _
MariaDB [(none)]> use restflask
' k' D( K5 Y# dDatabase changed- C( k, x; R" t* P& }" J
MariaDB [restflask]> show tables;
+ Z8 W" b3 ?4 WEmpty set (0.000 sec)# q4 c& {% i3 q: S2 r
6 q  a% u  d  e) m
MariaDB [restflask]> exit9 j4 {9 V  p1 r  R. T! E4 N( r) o
Bye
9 h" b, S& B, B! u- W- ?8 N[root@python-flask mysqlclient-2.2.4]# mysql -u victor -p -h 192.168.13.131/ r* ~5 W% J& }/ c3 O" Z
Enter password:
/ y& R% p% v$ \) U! EWelcome to the MariaDB monitor.  Commands end with ; or \g.
0 ~0 q! k1 y7 w& Z8 J& DYour MariaDB connection id is 173 k, F8 ~: Z3 @& z! i! w4 D9 `
Server version: 10.5.22-MariaDB MariaDB Server# ?, r! S: q" w$ b5 y+ Y
9 G! e- i8 o6 T1 F( O( x
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
9 I6 c0 j3 R1 [
8 I! \3 ?5 q- r5 J9 aType 'help;' or '\h' for help. Type '\c' to clear the current input statement.- g% u) i' P3 Z% E

# P8 {; i! A6 {( IMariaDB [(none)]> exit
! U0 v6 E" Q% Z3 K3 tBye7 T) n* i  Z9 K7 ~

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2024-7-25 07:18:15 | 显示全部楼层
MariaDB [(none)]>  create user victor@'%' identified by 'xxxx';1 J0 |9 t- H/ H. ?& N
Query OK, 0 rows affected (0.004 sec)1 f. I' C' V0 b4 U- x8 s& k- |
1 S; J/ |  z( R3 P5 q  ]# H
MariaDB [(none)]> grant ALL PRIVILEGES on testflask.* to victor@'%' identified by 'xxxx';
7 n: O4 w& S& s6 {7 wQuery OK, 0 rows affected (0.001 sec)
$ }  o! r) E6 e
  M# J- Z0 M8 K* t; e: s2 o$ M8 Q! @4 b# KMariaDB [(none)]> grant ALL PRIVILEGES on testflask.* to victor@'localhost' identified by 'xxxx';
( a8 r; E: ^. `( g% f1 q# t. L* w* rQuery OK, 0 rows affected (0.002 sec)6 ?, |( u2 L! L. w, G% u8 }" 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 */ ;
$ A6 H5 K% |8 N7 {( R  ?* zQuery OK, 1 row affected (0.005 sec)
% r5 S+ E& v7 \

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2024-7-30 22:54:02 | 显示全部楼层
MariaDB [(none)]> show create database testflask3 x5 z0 e# f6 g% A6 B: t1 S. j
    -> ;. n* |; `8 q+ X4 Y
+-----------+--------------------------------------------------------------------------------------------------+* C3 o7 T' f/ M* j/ y1 Q
| Database  | Create Database                                                                                  |
, z) A( G1 x9 k. @$ U$ h* y3 U1 E" K+-----------+--------------------------------------------------------------------------------------------------+9 C- i+ g6 Q: U) B1 x1 `
| testflask | CREATE DATABASE `testflask` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci */ |
7 k5 v3 G* `' O- O7 g: M+-----------+--------------------------------------------------------------------------------------------------+
6 s7 m% U1 V: E: Z4 k1 row in set (0.001 sec)
  |# ~+ W/ F; `- a& b8 h8 s% ~
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-12 00:51 , Processed in 0.023324 second(s), 21 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

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