当前位置:网站首页>Basic operation of MySQL database: import hellodb SQL and query as required; Create account and authorize
Basic operation of MySQL database: import hellodb SQL and query as required; Create account and authorize
2022-06-28 23:34:00 【njsummer】
1. Import hellodb.sql Generate database
# This time CentOS8.5 Operating system and MySQL5.7.36 The complete
mysql> select version();
+
--
--
--
--
--
--
+
| version() |
+
--
--
--
--
--
--
+
|
5.7.36-log |
+
--
--
--
--
--
--
+
1 row
in
set (0.00 sec)
[[email protected] ]
#mysql -uroot -ps*****2
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
8
Server version:
5.7.36-log Source distribution
Copyright (c)
2000,
2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type
'help;' or
'\h'
for help. Type
'\c' to
clear the current input statement.
mysql> show tables;
ERROR
1046 (3D000): No database selected
mysql> show databases;
+
--
--
--
--
--
--
--
--
--
--
+
| Database |
+
--
--
--
--
--
--
--
--
--
--
+
| information_schema |
| mysql |
| mytestdb1 |
| performance_schema |
| sys |
+
--
--
--
--
--
--
--
--
--
--
+
5 rows
in
set (0.06 sec)
mysql> quit
# Import database and verify
[[email protected] ]
#mysql -uroot -ps*****2 < /data/hellodb_innodb.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[[email protected] ]
#mysql -uroot -ps*****2
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
10
Server version:
5.7.36-log Source distribution
Copyright (c)
2000,
2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type
'help;' or
'\h'
for help. Type
'\c' to
clear the current input statement.
mysql> show databases;
+
--
--
--
--
--
--
--
--
--
--
+
| Database |
+
--
--
--
--
--
--
--
--
--
--
+
| information_schema |
| hellodb |
| mysql |
| mytestdb1 |
| performance_schema |
| sys |
+
--
--
--
--
--
--
--
--
--
--
+
6 rows
in
set (0.00 sec)
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
1.1 stay students In the table , Query age is greater than 25 year , And the name and age of the male students
# Get into hellodb database
mysql> use hellodb
Reading table information
for completion of table and column names
You can turn off this feature to
get a quicker startup with
-A
Database changed
# stay students In the table , Query age is greater than 25 year , And the name and age of the male students
mysql> select name,age from students where
gender
=
'M' and age>25;
+
--
--
--
--
--
--
--
+
--
--
-
+
| name | age |
+
--
--
--
--
--
--
--
+
--
--
-
+
| Xie Yanke |
53 |
| Ding Dian |
32 |
| Yu Yutong |
26 |
| Shi Qing |
46 |
| Tian Boguang |
33 |
| Xu Xian |
27 |
| Sun Dasheng |
100 |
+
--
--
--
--
--
--
--
+
--
--
-
+
7 rows
in
set (0.02 sec)
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
1.2 With ClassID To group by , Show the average age of each group
mysql> select classid,avg(age) from students group by classid;
+
--
--
--
--
-
+
--
--
--
--
--
+
| classid | avg(age) |
+
--
--
--
--
-
+
--
--
--
--
--
+
| NULL |
63.5000 |
|
1 |
20.5000 |
|
2 |
36.0000 |
|
3 |
20.2500 |
|
4 |
24.7500 |
|
5 |
46.0000 |
|
6 |
20.7500 |
|
7 |
19.6667 |
+
--
--
--
--
-
+
--
--
--
--
--
+
8 rows
in
set (0.02 sec)
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
1.3 According to the first 2 The average age in the questions is greater than 30 And the average age
mysql> select classid,avg(age) from students group by classid having avg(age)>30;
+
--
--
--
--
-
+
--
--
--
--
--
+
| classid | avg(age) |
+
--
--
--
--
-
+
--
--
--
--
--
+
| NULL |
63.5000 |
|
2 |
36.0000 |
|
5 |
46.0000 |
+
--
--
--
--
-
+
--
--
--
--
--
+
3 rows
in
set (0.01 sec)
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
1.4 Display with L Information about the students with the first name
mysql> select * from students where name like
'L%';
+
--
--
--
-
+
--
--
--
--
--
--
-
+
--
--
-
+
--
--
--
--
+
--
--
--
--
-
+
--
--
--
--
--
-
+
| StuID | Name | Age | Gender | ClassID | TeacherID |
+
--
--
--
-
+
--
--
--
--
--
--
-
+
--
--
-
+
--
--
--
--
+
--
--
--
--
-
+
--
--
--
--
--
-
+
|
8 | Lin Daiyu |
17 | F |
7 | NULL |
|
14 | Lu Wushuang |
17 | F |
3 | NULL |
|
17 | Lin Chong |
25 | M |
4 | NULL |
+
--
--
--
-
+
--
--
--
--
--
--
-
+
--
--
-
+
--
--
--
--
+
--
--
--
--
-
+
--
--
--
--
--
-
+
3 rows
in
set (0.00 sec)
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
2. Database authorization magedu user , allow 192.168.1.0/24 Segments can be connected mysql
# Create user
mysql> create user
'magedu'@
'192.168.1.%' identified by
'centos';
Query OK,
0 rows affected (0.06 sec)
mysql> show grants
for [email protected]
'192.168.1.%';
+
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
+
| Grants
for [email protected]% |
+
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
+
| GRANT USAGE ON *.* TO
'magedu'@
'192.168.1.%' |
+
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
+
1 row
in
set (0.00 sec)
# to grant authorization
mysql> grant all on *.* to [email protected]
'192.168.1.%' identified by
'centos';
Query OK,
0 rows affected,
1 warning (0.01 sec)
mysql> show grants
for [email protected]
'192.168.1.%';
+
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
-
+
| Grants
for [email protected]% |
+
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
-
+
| GRANT ALL PRIVILEGES ON *.* TO
'magedu'@
'192.168.1.%' |
+
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
-
+
1 row
in
set (0.00 sec)
mysql>
# Query all accounts in the database
mysql> SELECT DISTINCT CONCAT(
'User: '
'',user,
''
'@'
'',host,
''
';') AS query FROM mysql.user;
+
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
+
| query |
+
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
+
| User:
'shone'@
'%'; |
| User:
'magedu'@
'192.168.1.%'; |
| User:
'summer'@
'192.168.1.%'; |
| User:
'mysql.session'@
'localhost'; |
| User:
'mysql.sys'@
'localhost'; |
| User:
'root'@
'localhost'; |
+
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
+
6 rows
in
set (0.02 sec)
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
边栏推荐
- [state machine design] Moore, Mealy state machine, three-stage, two-stage and one-stage state machine writing specification
- Insomnia last night
- 第五章 虚拟存储器 练习
- What is the lifecycle of automated testing?
- TDD案例实战
- VSCode里使用条件断点(基于GDB)
- 华为22级专家十年心血终成云原生服务网格进阶实战文档,是真的6
- 机器学习4-降维技术
- 图片64base转码与解码
- Non scientific class! The road of self-study!
猜你喜欢

stm32F407-------NVIC中断优先级管理

With a monthly salary of 60000 yuan, such people began to be robbed after the Internet "reduced costs and increased efficiency"

Lock4j -- distributed locking Middleware -- use / instance

IDC: Alibaba cloud ranks first in the market share of China's data governance platform in 2021

【OpenCV】—线性滤波:方框滤波、均值滤波、高斯滤波

两栏布局左边图片显示部分由右边内容高度决定

VSCode里使用条件断点(基于GDB)

Don't ask me how to do UI automation test again

YuMinHong set up two funds funded by his hometown

Analysis of CSRF Cross Site Request Forgery vulnerability
随机推荐
[conception de la machine d'état] Moore, Mealy State Machine, Three - stage, Two - stage, one - stage State Machine Writing Specification
The picture display on the left of the two column layout is determined by the content height on the right
[mathematical modeling] fmincon() function of MATLAB nonlinear programming
Cs5463 code module analysis (including download link)
Is it safe to open a stock account on the Internet?
VSCode里使用条件断点(基于GDB)
两栏布局左边图片显示部分由右边内容高度决定
2022-06-28: what does the following golang code output? A:true; B:false; C:panic; D: Compilation failed. package main import “fm
mysql-5.7.30-winx64免安装版下载安装教程
That's how he did it!
【软件分析】软件分析、设计与建模迭代式详解
[数学建模]Matlab非线性规划之fmincon()函数
Use conditional breakpoints in vscode (based on GDB)
Ahai's advice
机器学习6-决策树
[stm32 Hal library] serial port communication
Chapter IV memory management exercise
【Flutter 問題系列第 71 篇】Flutter 中 Uint8List 和 Image 之間的相互轉換
解决ConfigParser解析中文问题
Association line exploration, how to connect the two nodes of the flow chart