当前位置:网站首页>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.
边栏推荐
- The picture display on the left of the two column layout is determined by the content height on the right
- Form verification problem - El select (solution to automatically trigger verification on initialization page)
- 设计电商秒杀系统
- Windows10 phpstudy installing redis extension
- [matlab] function definition and use
- Puma joins hands with 10ktf shop to launch its Web3 cooperation project with the largest scale so far
- ctfshow XSS
- [数学建模]Matlab非线性规划之fmincon()函数
- C语言-单词分析解析
- Save data in Excel: use openpyxl to create multiple tables and set excel row limit
猜你喜欢

window10 phpstudy 安装redis扩展

Learn binary tree like this

第五章 虚拟存储器 练习

note

One card can sell tens of millions, and the business expansion is faster than that of players: you don't understand the Jianghu of star cards

Matlab learning notes (6) upsample function and downsample function of MATLAB

See fengzhixia | FENGZikai, the originator of Guoman, for exclusive sale of Digital Collections

Lock4j -- distributed locking Middleware -- use / instance
![[opencv] - linear filtering: box filtering, mean filtering, Gaussian filtering](/img/1d/3a46517cbfa90005a15d7858d81ca9.png)
[opencv] - linear filtering: box filtering, mean filtering, Gaussian filtering
![[stm32 HAL库] RTC和BKP驱动](/img/72/c2c46377d0a2a5a032802640ca0201.png)
[stm32 HAL库] RTC和BKP驱动
随机推荐
Class extension and optional type extension of dart
Undefined symbol main (referred from entry9a.o).
[API packet capturing in selenium automation] installation and configuration of browsermobproxy
C language - word analysis
ERROR 1067 (42000): Invalid default value for ‘end_time‘ Mysql
LINQ linked table query
The picture display on the left of the two column layout is determined by the content height on the right
[opencv] - linear filtering: box filtering, mean filtering, Gaussian filtering
[stm32 Hal library] serial port communication
Chapter V virtual memory exercise
2022年PMP项目管理考试敏捷知识点(4)
VSCode里使用条件断点(基于GDB)
frameworks/base/core/res/res/values/symbols. Xml:3915: error: no definition for declared symbol solution
[matlab] function definition and use
O & M troubleshooting - use hcache plug-in to troubleshoot excessive buffer/cache occupancy
Scrapy使用xlwt实现将数据以Excel格式导出的Exporter
IDC: Alibaba cloud ranks first in the market share of China's data governance platform in 2021
移动端异构运算技术 - GPU OpenCL 编程(基础篇)
Insomnia last night
C語言-單詞分析解析