MySQL-第一章 介绍与安装

额外学习

1)内置函数
2)存储过程
3)函数
4)触发器
5)事件
6)视图
7)JSON语法

1.MySQL介绍与安装

1.1什么是数据

1.2数据库管理系统(DBMS)

RDBMS:关系型
NoSQL:非关系型
NewSQL:分布式型

1.3例题

笔试:请你列举熟悉的数据库产品?

RDBMS:Oracle ,MySQL ,MSSQL,PG
NoSQL:Redis ,MongoDB ,ES
NewSQL:TiDB(pingCap),Spanner(Google),OceanBase(alibaba)

面试:你们公司用了那些数据库产品?

MySQL,Redis,MongoDB,ES
引出 版本 MySQL 5.7.20
引出 公司 数据库架构
引出 公司 备份策略
引出 公司 遇到的故障和性能问题
总结:。。

1.4MySQL 软件分支

Oracle MySQL
MariaDB
PerconaDB
云数据(RDS MySQL,腾讯DB等)

1.5MySQL企业版本选择

1.5.1企业主流版本
大版本 小版本
5.6 5.6.34 , 5.6.36, 5.6.38, 5.6.40
5.7 5.7.18 , 5.7.19, 5.7.20 ,5.7.24

一定选择GA版本

关于版本GA时间
5.6.38 , 5.7.20 --稳定发布时间--20190913

1.5.2企业版本新环境建议

5.7 版本 GA 6-12 月版本 偶数版

2. MySQL 5.7.26 二进制版规划和部署

2.1规划:

规划 详细参数
硬件环境 DELL R720,CPU28,MEM128G,RAID 108*600G SAS
OS CentOS 7.6.1810,3.10.0-862.el7.x86_64
网络环境 eth0:100.0.0.51/24 ,hostname:db01
存储 /dev/sdb 20G

2.2 实施:

2.2.1创建目录
[root@db01 ~]# mkdir /application               ---软件的存放目录
[root@db01 ~]# mkdir /data/3306/data -p                  ---数据的存放位置
2.2.2创建用户
[root@db01 ~]# useradd mysql -s /sbin/nologin -M 
2.2.3 上传软件并解压处理

上传解压(略.)

[root@db01 /application]# tar xf  mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
[root@db01 /application]# mv mysql-5.7.26-linux-glibc2.12-x86_64 mysql
2.2.4 数据初始化
[root@db01 ~]# rpm -qa|grep maria
mariadb-libs-5.5.60-1.el7_5.x86_64
[root@db01 ~]# yum  remove mariadb-libs-5.5.60-1.el7_5.x86_64 -y
[root@db01 ~]# vim /etc/profile
export PATH=/application/mysql/bin:$PATH
[root@db01 ~]# mysqld --initialize-insecure --user=mysql --basedir=/application/mysql --datadir=/data/3306/data
2.2.5 书写配置文件
cat >/etc/my.cnf <
2.2.6 准备启动脚本
[root@db01 ~]#  chown -R mysql:mysql /application
[root@db01 ~]#  chown -R mysql:mysql /data

[root@db01 /application/mysql/support-files]# cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@db01 /application]# /etc/init.d/mysqld start 
Starting MySQL.Logging to '/data/3306/data/db01.err'.
 SUCCESS!

检查:
[root@db01 /application]# ps -ef |grep mysqld 
root       4226      1  0 13:10 pts/0    00:00:00 /bin/sh /application/mysql/bin/mysqld_safe --datadir=/data/3306/data --pid-file=/data/3306/data/db01.pid
mysql      4365   4226  0 13:10 pts/0    00:00:00 /application/mysql/bin/mysqld --basedir=/application/mysql --datadir=/data/3306/data --plugin-dir=/application/mysql/lib/plugin --user=mysql --log-error=db01.err --pid-file=/data/3306/data/db01.pid --socket=/tmp/mysql.sock
root       4398   1617  0 13:15 pts/0    00:00:00 grep --color=auto mysqld
[root@db01 /application]# ss -lnp |grep mysqld 
u_str  LISTEN     0      80     /tmp/mysql.sock 55045                 * 0                   users:(("mysqld",pid=4365,fd=21))
tcp    LISTEN     0      80       :::3306                 :::*                   users:(("mysqld",pid=4365,fd=16))
[root@db01 /application]# netstat -lntup |grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      4365/mysqld 

2.3细节说明

2.3.1命令初始化
mysqld --initialize-insecure --user=mysql --basedir=/application/mysql --datadir=/data/3306/data

数据初始化,形成文件

[root@db01 ~]# ll /data/3306/data/
total 122924
-rw-r----- 1 mysql mysql       56 Aug  5 12:37 auto.cnf
-rw-r----- 1 mysql mysql     3332 Aug  5 13:22 db01.err
-rw-r----- 1 mysql mysql        5 Aug  5 13:10 db01.pid
-rw-r----- 1 mysql mysql      419 Aug  5 12:37 ib_buffer_pool
-rw-r----- 1 mysql mysql 12582912 Aug  5 13:10 ibdata1
-rw-r----- 1 mysql mysql 50331648 Aug  5 13:10 ib_logfile0
-rw-r----- 1 mysql mysql 50331648 Aug  5 12:37 ib_logfile1
-rw-r----- 1 mysql mysql 12582912 Aug  5 13:10 ibtmp1
drwxr-x--- 2 mysql mysql     4096 Aug  5 12:37 mysql
drwxr-x--- 2 mysql mysql     8192 Aug  5 12:37 performance_schema
drwxr-x--- 2 mysql mysql     8192 Aug  5 12:37 sys
2.3.2参数说明:

--initialize-insecure 启用非安全模式,进行数据初始化
--initialize 安全模式
版本5.7之后,加强了用户密码安全管理功能
(1)密码长度 12位
(2)密码复杂度 4种数字大写小写特殊符号
(3)初始化时自动生成密码

扩展:
版本5.6 初始化方式

/application/mysql/scripts/mysql_install_db  --user=mysql --basedir=/application/mysql --datadir=/data/3306/data
2.3.3启动方式说明

systemd (centos 7)

启动1:/etc/init.d/mysqld start
启动2:service mysqld start

cat > /etc/systemd/system/mysqld.service <

sys -V(centos 6)
service xxx start stop restart status

3.同主机版本升级(扩展)

3.1备份

3.2部署8.0环境

[root@db01 ~]# tar xf mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz
[root@db01 ~]# mv mysql-8.0.16-linux-glibc2.12-x86_64 mysql8

3.3停止原库
[root@db01 /application]# systemctl stop mysqld
3.4 修改已有配置

修改环境变量
vim  /etc/profile 
export PATH=/application/mysql8/bin:$PATH
[root@db01 /application]# source /etc/profile 

查看软件版本
[root@db01 /application]# mysql -V 
mysql  Ver 8.0.16 for linux-glibc2.12 on x86_64 (MySQL Community Server - GPL)

修改配置文件
[root@db01 /application]# vim /etc/my.cnf
[mysqld]
user=mysql
basedir=/application/mysql8
datadir=/data/3306/data
socket=/tmp/mysql.sock
[mysql]
socket=/tmp/mysql.sock

3.5修改system启动脚本

[root@db01 /application]# vim /etc/systemd/system/mysqld.service 
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/application/mysql8/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000                 

3.6数据升级(此步骤8.0可以省略)

[root@db01 /application]# mysql_upgrade
The mysql_upgrade client is now deprecated. The actions executed by the upgrade client are now done by the server.
To upgrade, please start the new MySQL binary with the older data directory. Repairing user tables is done automatically. Restart is not required after upgrade.
The upgrade process automatically starts on running a new MySQL binary with an older data directory. To avoid accidental upgrades, please use the --upgrade=NONE option with the MySQL binary. The option --upgrade=FORCE is also provided to run the server upgrade sequence on demand.
It may be possible that the server upgrade fails due to a number of reasons. In that case, the upgrade sequence will run again during the next MySQL server start. If the server upgrade fails repeatedly, the server can be started with the --upgrade=MINIMAL option to start the server without executing the upgrade sequence, thus allowing users to manually rectify the problem.

4.简单管理操作

修改密码
[root@db01 /application]# mysqladmin -uroot -p password 123 
Enter password: 
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
登录
[root@db01 /application]# mysql  -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.7.26 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
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>
查看用户名密码
mysql> select user,host ,authentication_string from mysql.user;
+---------------+-----------+-------------------------------------------+
| user          | host      | authentication_string                     |
+---------------+-----------+-------------------------------------------+
| root          | localhost | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
| mysql.session | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| mysql.sys     | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
+---------------+-----------+-------------------------------------------+
3 rows in set (0.00 sec)

OVER ! ! !

你可能感兴趣的:(MySQL-第一章 介绍与安装)