DataBase Management System
)结构化数据:数据库存放的数据
半结构化数据:文本文件
非结构化数据:图片,视频
表由行和列组成 记录:(行) 条 字段:(列) 个
主键约束:一个或多个字段的组合,填入的数据必须能在本表中唯一标识本行,提供数据,不能为空
惟一键约束:个或多个字段的组合,填入的数据必须能在本表中唯一标识本行,允许为空
外键约束:一个表中的某字段可填入数据取决于另一个表的主键已有的数据
检查性约束
针对数据库,表,用户,索引,视图,存储过程,存储函数,触发器,事件调度器
针对表,增删改查
[root@SYL4 ~]# wget http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
[root@SYL4 ~]# ls
anaconda-ks.cfg mysql57-community-release-el7-10.noarch.rpm
[root@SYL4 ~]# yum list all|grep mysql57-community
Failed to set locale, defaulting to C.UTF-8
[root@SYL4 ~]# rpm -ivh mysql57-community-release-el7-10.noarch.rpm
warning: mysql57-community-release-el7-10.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:mysql57-community-release-el7-10 ################################# [100%]
[root@SYL4 ~]#
[root@SYL4 ~]# wget https://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-client-5.7.37-1.el7.x86_64.rpm https://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-common-5.7.37-1.el7.x86_64.rpm https://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-devel-5.7.37-1.el7.x86_64.rpm https://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-libs-5.7.37-1.el7.x86_64.rpm https://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-server-5.7.37-1.el7.x86_64.rpm
[root@SYL4 ~]# ls
anaconda-ks.cfg
mysql-community-client-5.7.37-1.el7.x86_64.rpm
mysql-community-common-5.7.37-1.el7.x86_64.rpm
mysql-community-devel-5.7.37-1.el7.x86_64.rpm
mysql-community-libs-5.7.37-1.el7.x86_64.rpm
mysql-community-server-5.7.37-1.el7.x86_64.rpm
[root@SYL4 ~]# yum -y install *.rpm
[root@SYL4 ~]# systemctl enable --now mysqld
[root@SYL4 ~]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enab>
Active: active (running) since Mon 2022-04-18 17:31:04 CST; >
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 135835 ExecStart=/usr/sbin/mysqld --daemonize --pid->
Process: 135442 ExecStartPre=/usr/bin/mysqld_pre_systemd (cod>
Main PID: 135837 (mysqld)
Tasks: 27 (limit: 11216)
Memory: 301.1M
CGroup: /system.slice/mysqld.service
└─135837 /usr/sbin/mysqld --daemonize --pid-file=/va>
Apr 18 17:30:58 SYL4 systemd[1]: Starting MySQL Server...
Apr 18 17:31:04 SYL4 systemd[1]: Started MySQL Server.
[root@SYL4 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:PortProcess
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 80 *:3306 *:*
[root@SYL4 ~]#
[root@SYL4 ~]# grep 'password' /var/log/mysqld.log
2022-04-18T09:31:00.145440Z 1 [Note] A temporary password is generated for root@localhost: 3W(phUO)_a0z
[root@SYL4 ~]# mysql -uroot -p'3W(phUO)_a0z'
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 3
Server version: 5.7.37
Copyright (c) 2000, 2022, 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> set password = password('Run123456!');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> quit
[root@SYL4 ~]# mysql -uroot -p'Run123456!';
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 4
Server version: 5.7.37 MySQL Community Server (GPL)
Copyright (c) 2000, 2022, 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> quit
Bye
[root@SYL4 ~]#
为避免mysql自动升级,这里需要卸载最开始安装的yum源
[root@SYL4 ~]# rpm -e mysql57-community-release
虚拟机的权限
主机ip | 服务器ip | 客户机ip |
---|---|---|
192.168.232.1 | 192.168.232.132 | 192.168.232.129 |
mysql> GRANT all ON *.* TO 'root'@'192.168.232.1' IDENTIFIED B
Y 'Run123456!';
Query OK, 0 rows affected, 1 warning (0.13 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.22 sec)
[root@SYL4 ~]# systemctl disable --now firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@SYL4 ~]# setenforce 0
[root@SYL4 ~]# vim /etc/selinux/config
[root@SYL4 ~]# cat /etc/selinux/config |grep SELINUX
# SELINUX= can take one of these three values:
SELINUX=disabled
# SELINUXTYPE= can take one of these three values:
SELINUXTYPE=targeted
[root@SYL4 ~]#
设置权限
mysql> GRANT all ON *.* TO 'root'@'192.168.232.129' IDENTIFIED BY 'Run123456!';
Query OK, 0 rows affected, 1 warning (0.18 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.18 sec)
与客户机的连接
[root@SYL2 ~]# ip a
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:ce:9c:21 brd ff:ff:ff:ff:ff:ff
inet 192.168.232.129/24 brd 192.168.232.255 scope global noprefixroute ens33
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fece:9c21/64 scope link
valid_lft forever preferred_lft forever
//客户机第二台虚拟机
[root@SYL2 ~]# mysql -uroot -p'Run123456!' -h192.168.232.132
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 16
Server version: 5.7.37 MySQL Community Server (GPL)
Copyright (c) 2000, 2022, 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> quit
-uUSERNAME //指定用户名,默认为root
-hHOST //指定服务器主机,默认为localhost,推荐使用ip地址
-pPASSWORD //指定用户的密码
-P# //指定数据库监听的端口,这里的#需用实际的端口号代替,如-P3307
-V //查看当前使用的mysql版本
-e //不登录mysql执行sql语句后退出,常用于脚本
[root@SYL4 ~]# mysql -V
mysql Ver 14.14 Distrib 5.7.37, for Linux (x86_64) using EditLine wrapper
[root@SYL4 ~]#
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.30 sec)
mysql> quit
Bye
[root@SYL4 ~]#
[root@SYL4 ~]# mysql -uroot -p'Run123456!' -e 'SHOW DATABASES';
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
[root@SYL4 ~]#
[root@SYL4 ~]# mysql -uroot -p -e 'SHOW DATABASES';
Enter password:
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
[root@SYL4 ~]#