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

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

[复制链接]

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
发表于 2024-7-23 15:43:31 | 显示全部楼层 |阅读模式
创建mysql用户并创建对应的访问库
/ f9 A/ j, }) I) q! K/ @/ w' g% @* ^. q( _( _: r
/ j8 i# L( M. L
MariaDB [(none)]>  select distinct(User) from mysql.user;# P0 a5 ~& T" C3 b
+-------------+
7 Q; i! D6 c, j! W  t) X0 m| User        |7 g7 ^$ l& F) s  p
+-------------+
+ r' I; R* r6 H) G| mariadb.sys |
1 O  I* ]7 i) G* r$ s% f| mysql       |
% I$ l( ^' {4 L| root        |
9 i0 {) _3 I0 W+-------------+
# S3 ]: T2 Z/ m7 ~3 rows in set (0.003 sec)
4 x5 k$ f- h$ ~& Q6 ^
% B" |1 W& l' s, bMariaDB [(none)]> create user victor@'%' identified by 'victzzzz';# O7 `9 H/ P; _0 @2 A  Q& x" ~# i
Query OK, 0 rows affected (0.003 sec)
8 Y) Z* }$ e# m7 F% y7 j1 O9 {( @: V9 N; z
MariaDB [(none)]> grant ALL PRIVILEGES on restflask.* to victor@'%' identified by 'victzzzz';* P& s- h5 c+ a& ]
Query OK, 0 rows affected (0.001 sec)! L0 x3 Z" X( T  k2 |- \2 F

! O/ s5 J0 V# u0 j( P8 l9 o3 qMariaDB [(none)]> grant ALL PRIVILEGES on restflask.* to victor@'localhost' identified by 'victzzzz';
% |4 A4 j& Q' C9 [Query OK, 0 rows affected (0.002 sec)
- z6 I1 _3 v; a' W& G" ]- j- b1 B
3 G1 Z/ W# W. q+ m+ A# i) t+ x: X

6 Z3 n. x7 R2 u- F- L2 {9 IMariaDB [(none)]> create user victor@'%' identified by 'victxxxx;
$ J7 h# j# c  P1 R) zQuery OK, 0 rows affected (0.003 sec)6 H1 z9 p! i4 y' v

8 j" \& r; ]6 c  ?# d$ |MariaDB [(none)]> create user victor@'localhost' identified by 'victxxxx';
6 Y2 Q' @' I1 b8 A% D) \Query OK, 0 rows affected (0.001 sec). c; m/ f  v8 i

% x1 R! s! p+ Y$ {. Q" v5 _( ~4 l; R4 Y. p8 K2 s* u! f5 Y# g

0 z5 l. V# f) O4 q# X( r, u1 t  Y. T' X; o

0 o1 `1 r$ V( s7 P: M6 |  c- I6 L+ f, l; g$ |- G

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2024-7-23 15:44:09 | 显示全部楼层
MariaDB [(none)]> create database restflask ;) N9 v& y' U0 J) X
Query OK, 1 row affected (0.001 sec)% D5 j( b: S$ u/ S+ G' W8 \

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2024-7-23 16:00:24 | 显示全部楼层
测试连接 带ip地址访问:
5 U" Z4 O9 \2 m1 c mysql -u victor -p! P6 z% m" q/ `) U" J4 l
Enter password: & @. x# x" x0 U, c  H
Welcome to the MariaDB monitor.  Commands end with ; or \g.
' P! o; @7 A, ?5 H+ K4 RYour MariaDB connection id is 16
9 Y/ @; u: s) W$ o5 b$ g2 tServer version: 10.5.22-MariaDB MariaDB Server9 T! y0 {- r  d

0 o: W2 k3 N. n0 _Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
/ Y5 }; H* Y6 i  s, [2 r' S9 M5 e1 x, G3 S+ m
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
4 e0 _- d" t9 H# P* B) B1 H, D' N: m0 S) y( w6 R$ L) z
MariaDB [(none)]> show databases;
1 Q8 t. ^3 r# ~- o- Q7 n+--------------------+& ?" v, Z  [4 d- P9 K/ Q1 G+ {% |
| Database           |
/ p* f# m2 [- c1 n+--------------------+
3 n% n3 a5 m- O& L% r6 E| information_schema |6 ?+ Z: i- O) _+ i5 c' a
| restflask          |
2 ^! d7 P$ m$ d) \5 M% T+--------------------+
( {4 V; p! L0 m) U( a% ?1 R3 @2 rows in set (0.001 sec)4 p# y. i2 D: j8 y+ P. w0 O8 T

: R0 U- ~  y3 J4 e$ g7 xMariaDB [(none)]> use restflask3 Q3 o; M) f; [( Z% Z* J" e
Database changed
, l- Y/ s: ?* l# O; ZMariaDB [restflask]> show tables;
8 _; s& a( R1 @6 EEmpty set (0.000 sec)
, [) Z( V! k  I7 H/ |6 F" @. R' H1 W! H6 C/ \+ F1 I& ?
MariaDB [restflask]> exit
& F! F5 v7 V1 n6 n% [" K3 aBye# p8 z4 V8 s# T7 `7 _
[root@python-flask mysqlclient-2.2.4]# mysql -u victor -p -h 192.168.13.131
. x* G0 k0 a" K# _3 REnter password:
; p3 g0 ^+ y7 _4 Z9 [, J' wWelcome to the MariaDB monitor.  Commands end with ; or \g.
( z6 X( D# b4 f! vYour MariaDB connection id is 17& N; k" Z* V# H7 m8 U. ~
Server version: 10.5.22-MariaDB MariaDB Server
: R9 {- u; f# a6 Z9 [0 ?; U1 H9 W2 J8 n: |! S" u
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.) `( t/ K7 x+ y1 i' M, C
' \" x8 ]. Y  ]$ V
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
) p+ O7 a  X( l  j, q' z8 g8 V. W% A6 v7 E$ |/ f
MariaDB [(none)]> exit
; a0 _4 B  F& fBye
& F$ S. l0 a# j0 i/ x

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2024-7-25 07:18:15 | 显示全部楼层
MariaDB [(none)]>  create user victor@'%' identified by 'xxxx';
  i8 [) i- _& [9 v$ rQuery OK, 0 rows affected (0.004 sec)
5 B' l" d& c# Q4 A  U, T  a5 P  l, J* h0 a: |% T8 K$ N
MariaDB [(none)]> grant ALL PRIVILEGES on testflask.* to victor@'%' identified by 'xxxx';, Y: N) l1 R- o
Query OK, 0 rows affected (0.001 sec)
: W, K5 A2 `7 z/ h$ D8 M" i8 u
8 |+ R0 J# ?$ z7 H; Z8 P* aMariaDB [(none)]> grant ALL PRIVILEGES on testflask.* to victor@'localhost' identified by 'xxxx';
% W3 f6 {; Z! j0 l+ _3 F7 uQuery OK, 0 rows affected (0.002 sec)+ O; I) R6 P% t: I: U- Y6 o

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 */ ;
5 e% Z: m% S# S: w9 q" NQuery OK, 1 row affected (0.005 sec)
" k' H1 X! Y: v! G, S& Y& R, t

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2024-7-30 22:54:02 | 显示全部楼层
MariaDB [(none)]> show create database testflask$ G. {, N" G  {# u: I7 q1 S2 I2 ^
    -> ;0 P9 w1 Z+ u& e9 s' b: Z
+-----------+--------------------------------------------------------------------------------------------------+
1 g- D- j# Y' u4 B( L6 Y5 M| Database  | Create Database                                                                                  |. B( f) O. u5 z* D' A, S
+-----------+--------------------------------------------------------------------------------------------------+
! x3 K: E) |% I| testflask | CREATE DATABASE `testflask` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci */ |
% F5 ^3 b: y6 f4 F0 V/ i5 Q+-----------+--------------------------------------------------------------------------------------------------+
- Z, W* B+ M4 A& L6 l  u! l$ \; r6 u1 row in set (0.001 sec); s% V8 D; Q' D: E) f
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-12 02:51 , Processed in 0.026411 second(s), 22 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

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