day01-MySQL介绍及安装

day01-MySQL介绍及安装

加我微信:loveoracle11g(请备注:进mysql微信群)
拉你进MySQL高级DBA(技术开车群)微信群呕!!!


1、课程介绍
MySQL专职DBA课程更新中............................................
要求掌握80%以上相当于DBA中级以上,两年工作经验。
课程大纲:
(1).MySQL5.7二进制安装部署,编译安装自己扩展
(2).MySQL升级步骤扩展
(3).MySQL5.7体系结构原理
(4).MySQL基础管理
(5).基础SQL语句使用
(6).SQL高级应用
(7).Information_schema获取元数据
(8).索引、执行计划管理(基础优化)
(9).存储引擎
(10).日志管理
(11).备份与恢复
(12).主从复制及架构演变
(13).传统的高可用及读写分离(MHA&Atlas)
(14).传统分布式架构设计与实现-扩展(Mycat--->DBLE,DRDS)
(15).MySQL5.7高可用及分布式架构-扩展(MGR,InnoDB Cluster)
(16).MySQL优化(安全、性能)
(17).MySQL 监控(zabbix、Open-falcon)
(18).RDS(阿里云课程)
(19).NoSQL-Redis缓存技术
(20).NoSQL-MongoDB分布式数据库技术
(21).PG(了解)
(22).Oracle(了解)

2、官方定义的MySQL DBA工作职责 (1)开发DBA 懂至少一门开发语言:Java、Python 基本SQL语句深入学习(增删改查)、数据库结构设计(建模) 高级SQL:存储过程、函数、触发器、视图、事件 (2)运维DBA 初级运维DBA:各版本、各平台安装搭建、升级 中级运维DBA:基础管理(启动关闭、初始化配置文件管理、多实例管理)、基本SQL增删改查、体系结构原理、用户权限管理、索引管理、存储引擎、日志管理、备份恢复、主从复制(构建、状态监控)、故障处理。 高级运维DBA:性能优化、集群高可用。 3、DBA的职业素养 - 人品:贩卖数据,泄露数据。 - 严谨:规范操作,要有理论支撑或者实践检验(面试问你上一家DBA规范,说几条??) - 细心:变更类的操作,多思考。 - 心态:能顶住压力,别惹事,出事别怕事。 - 熟悉操作系统:精通操作系统。 - 熟悉公司业务(开发):业务是什么?产品的功能、用户的行为(热功能、热数据)。 - 熟悉行业发展趋势:数据库种类、数据库版本、数据库产品类型、什么企业用什么数据库。https://db-engines.com/en/ranking - 喜欢数据库:必须热爱喜欢数据库。 4、什么是数据库管理系统(DBMS)? RDBMS:关系型数据库管理系统 比较适合于,安全级别要求高的数据以及关系较复杂的数据 NoSQL:非关系型数据库管理系统 适合于高性能存取数据,一般是配合RDBMS进行使用的 针对大数据处理分析,分布式架构更加擅长 5、数据库管理系统种类 RDBMS:MySQL 、Oracle、SQL Server、PG NoSQL:Not Only SQL 键值对(key-value):Redis、Memcached 文档型(document):MongoDB 6、MySQL版本企业选择 规范: GA版本:稳定的发布版本。 版本类型: E:企业版,收费版本,SR,偏向传统行业。 C:社区版,开源版本,互联网企业的选择。 企业版本选择:一般新上的环境,会选择GA版6-12月的产品版本。 企业主流版本: 5.6版本:5.6.20 5.6.34 5.6.36 5.6.38 5.6.40 5.7版本:5.7.18 5.7.20 5.7.22 5.7.24 面试问:你们公司用什么版本的数据库呀? 5.6.38 5.7.20 面试问:你们公司怎么还在用这么低的版本? 我们这个业务已经运行4年了,一直用的5.6版本,非常稳定。 所以说暂时没有打算升级。(业务4年圆谎:大版本是5.6,中间有运维做过升级,我在公司不久。) GA时间问题漏洞怎么说? 刚去上家公司不到两年,上一个DBA交接的时候业务已经运行的两年多了,我接手的时候mysql的版本已经是5.6.38了 应当是做过小版本的升级。 我们公司现在用的是5.7的,你能胜任吗? 能。虽然我们生产中一直使用的5.6,但是我对5.7的新特性已经足够了解了。所以我完全能够胜任贵公司的工作。 7、MySQL分支: Oracle MySQL MariaDB PerconaDB RDS AliSQL 8、MySQL软件下载:GA时间记住 https://downloads.mysql.com/archives/community/ 输入:www.mysql.com 点击:downloads 点击:Archives 点击:MySQL Community Server 选择:Product Version:MySQL软件版本 选择:Operating System:二进制包、源码包 选择:OS Version:系统版本 --------------------------------------------------------------------- RPM包:Red Hat Enterprise Linux / Oracle Linux 二进制包:Linux - Generic(不需要二次开发和不需要添加功能) 源码包:Source Code(需要二次开发的时候,需要做统一配置管理的时候) MySQL是C++的源码开发的 研究源码 mysql-5.7.20 GA时间:2017-09-13 9、MySQL二进制安装 [root@mysql-node1 ~]# mkdir -p /app [root@mysql-node1 ~]# cd /app [root@mysql-node1 /app]# rz -y [root@mysql-node1 /app]# ls -lh total 612M -rw-r--r-- 1 root root 612M May 31 18:31 mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz [root@mysql-node1 /app]# du -sh * 2.5G mysql-5.7.20-linux-glibc2.12-x86_64 612M mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz [root@mysql-node1 /app]# rm -rf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz [root@mysql-node1 /app]# mv mysql-5.7.20-linux-glibc2.12-x86_64/ mysql [root@mysql-node1 /app]# ls -l total 0 drwxr-xr-x 9 root root 129 May 31 18:32 mysql [root@mysql-node1 /app]# cd mysql/ [root@mysql-node1 /app/mysql]# ls -l total 36 drwxr-xr-x 2 root root 4096 May 31 18:32 bin -rw-r--r-- 1 7161 31415 17987 Sep 13 2017 COPYING drwxr-xr-x 2 root root 55 May 31 18:32 docs drwxr-xr-x 3 root root 4096 May 31 18:32 include drwxr-xr-x 5 root root 229 May 31 18:32 lib drwxr-xr-x 4 root root 30 May 31 18:32 man -rw-r--r-- 1 7161 31415 2478 Sep 13 2017 README drwxr-xr-x 28 root root 4096 May 31 18:32 share drwxr-xr-x 2 root root 90 May 31 18:32 support-files [root@mysql-node1 ~]# vim /etc/profile export PATH=/app/mysql/bin:$PATH [root@mysql-node1 ~]# source /etc/profile [root@mysql-node1 ~]# mysql -V mysql Ver 14.14 Distrib 5.7.20, for linux-glibc2.12 (x86_64) using EditLine wrapper [root@mysql-node1 ~]# rpm -qa | grep mariadb mariadb-libs-5.5.60-1.el7_5.x86_64 [root@mysql-node1 ~]# yum -y remove mariadb-libs [root@mysql-node1 ~]# id mysql id: mysql: no such user [root@mysql-node1 ~]# useradd -s /sbin/nologin -M mysql [root@mysql-node1 ~]# id mysql uid=1000(mysql) gid=1000(mysql) groups=1000(mysql) [root@mysql-node1 ~]# mkdir -p /data [root@mysql-node1 ~]# chown -R mysql.mysql /app [root@mysql-node1 ~]# chown -R mysql.mysql /data [root@mysql-node1 ~]# rpm -qa | grep libaio libaio-devel-0.3.109-13.el7.x86_64 libaio-0.3.109-13.el7.x86_64 [root@mysql-node1 ~]# yum -y install libaio-devel 初始化数据库 5.6版本的初始化程序,初始化完成后:无密码和无安全策略的) /app/mysql/scripts/mysql_install_db \ --user=mysql \ --basedir=/app/mysql \ --datadir=/data/mysql 5.7版本的初始化程序,有两种初始化方式: (1).第一种初始化方式:开启临时密码和安全策略。 初始化数据,初始化管理员的临时密码。 /app/mysql/bin/mysqld --initialize \ --user=mysql \ --basedir=/app/mysql \ --datadir=/data/mysql (2).第二种初始化方式和之前一样,是无密码无安全策略的。 初始化数据,初始化管理员的密码为空。 /app/mysql/bin/mysqld --initialize-insecure \ --user=mysql \ --basedir=/app/mysql \ --datadir=/data/mysql 安全策略??? 密码的复杂度进行了要求,对于密码的过期时间设置了限制。 新特性重要说明: 5.7开始MySQL加入了全新的密码安全机制: 1.初始化完成后会生成临时密码(显示到屏幕上,并且会往日志中记一份) 2.密码复杂度:长度:超过12位?复杂度:字符混乱组合 3.密码过期时间180天。 [root@mysql-node1 ~]# /app/mysql/bin/mysqld --initialize-insecure \ > --user=mysql \ > --basedir=/app/mysql \ > --datadir=/data/mysql 2019-05-31T10:46:26.996991Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2019-05-31T10:46:27.519955Z 0 [Warning] InnoDB: New log files created, LSN=45790 2019-05-31T10:46:27.582510Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2019-05-31T10:46:27.651237Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 57b56216-8391-11e9-801c-000c292a0fe7. 2019-05-31T10:46:27.652082Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2019-05-31T10:46:27.652923Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option. 初始化参数介绍: --initialize-insecure \ 是用无安全限制的方式进行数据初始化 --user=mysql \ 设置数据的管理用户 --basedir=/app/mysql \ 软件的安装路径 --datadir=/data/mysql \ 数据的存储位置 [root@mysql-node1 ~]# cd /data/mysql/ [root@mysql-node1 /data/mysql]# ls -l total 110628 -rw-r----- 1 mysql mysql 56 May 31 18:46 auto.cnf -rw-r----- 1 mysql mysql 419 May 31 18:46 ib_buffer_pool -rw-r----- 1 mysql mysql 12582912 May 31 18:46 ibdata1 -rw-r----- 1 mysql mysql 50331648 May 31 18:46 ib_logfile0 -rw-r----- 1 mysql mysql 50331648 May 31 18:46 ib_logfile1 drwxr-x--- 2 mysql mysql 4096 May 31 18:46 mysql drwxr-x--- 2 mysql mysql 8192 May 31 18:46 performance_schema drwxr-x--- 2 mysql mysql 8192 May 31 18:46 sys 准备启动脚本和基础配置 [root@mysql-node1 ~]# vim /etc/my.cnf [mysqld] user=mysql basedir=/app/mysql datadir=/data/mysql/ server_id=1 port=3306 socket=/tmp/mysql.sock [mysql] socket=/tmp/mysql.sock [root@mysql-node1 ~]# cd /app/mysql/support-files/ [root@mysql-node1 /app/mysql/support-files]# ls -l total 24 -rw-r--r-- 1 mysql mysql 773 Sep 13 2017 magic -rwxr-xr-x 1 mysql mysql 1061 Sep 14 2017 mysqld_multi.server -rwxr-xr-x 1 mysql mysql 894 Sep 14 2017 mysql-log-rotate -rwxr-xr-x 1 mysql mysql 10576 Sep 14 2017 mysql.server [root@mysql-node1 /app/mysql/support-files]# cp mysql.server /etc/init.d/mysqld [root@mysql-node1 ~]# chmod 700 /etc/init.d/mysqld [root@mysql-node1 ~]# ls -l /etc/init.d/mysqld -rwx------ 1 root root 10576 May 31 18:56 /etc/init.d/mysqld [root@mysql-node1 ~]# /etc/init.d/mysqld start Starting MySQL.Logging to '/data/mysql/mysql-node1.err'. SUCCESS! [root@mysql-node1 ~]# ss -tunlp | grep mysql tcp LISTEN 0 80 :::3306 :::* users:(("mysqld",pid=7304,fd=16)) systemd管理mysql启动 [root@mysql-node1 ~]# vim /etc/systemd/system/mysqld.service [Unit] Description=MySQL Server Documentation=man:mysqld(8) Documentation=https://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=/app/mysql/bin/mysqld --defaults-file=/etc/my.cnf LimitNOFILE = 5000 [root@mysql-node1 ~]# /etc/init.d/mysqld stop Shutting down MySQL.. SUCCESS! [root@mysql-node1 ~]# systemctl status mysqld.service ● mysqld.service - MySQL Server Loaded: loaded (/etc/systemd/system/mysqld.service; disabled; vendor preset: disabled) Active: inactive (dead) Docs: man:mysqld(8) https://dev.mysql.com/doc/refman/en/using-systemd.html [root@mysql-node1 ~]# systemctl enable mysqld.service Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /etc/systemd/system/mysqld.service. [root@mysql-node1 ~]# systemctl start mysqld.service [root@mysql-node1 ~]# ss -tunlp | grep mysql tcp LISTEN 0 80 :::3306 :::* users:(("mysqld",pid=7482,fd=16)) [root@mysql-node1 ~]# ls -l /tmp/ total 4 srwxrwxrwx 1 mysql mysql 0 May 31 19:04 mysql.sock -rw------- 1 mysql mysql 5 May 31 19:04 mysql.sock.lock drwx------ 2 root root 6 May 31 18:21 vmware-root_5308-2823291926 [root@mysql-node1 ~]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.20 MySQL Community Server (GPL) Copyright (c) 2000, 2017, 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> select user(); +----------------+ | user() | +----------------+ | root@localhost | +----------------+ 1 row in set (0.00 sec) mysql> exit; Bye [root@mysql-node1 ~]# [root@mysql-node1 ~]# ps -elf | grep mysql 4 S mysql 7587 1 0 80 0 - 281410 poll_s 19:04 ? 00:00:00 /app/mysql/bin/mysqld --defaults-file=/etc/my.cnf 4 R root 7650 6751 0 80 0 - 28177 - 19:08 pts/0 00:00:00 grep --color=auto mysql [root@mysql-node1 ~]# ss -tunlp | grep mysql tcp LISTEN 0 80 :::3306 :::* users:(("mysqld",pid=7587,fd=16)) [root@mysql-node1 ~]# netstat -tunlp | grep mysql tcp6 0 0 :::3306 :::* LISTEN 7587/mysqld [root@mysql-node1 ~]# 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@mysql-node1 ~]# mysql -uroot -p123 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 6 Server version: 5.7.20 MySQL Community Server (GPL) Copyright (c) 2000, 2017, 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> exit ; Bye [root@mysql-node1 ~]# [root@mysql-node1 ~]# mysql -uroot -p -S /tmp/mysql.sock Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.20 MySQL Community Server (GPL) Copyright (c) 2000, 2017, 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> show databases ; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.01 sec) 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) mysql> exit ; Bye [root@mysql-node1 ~]#

猜你喜欢

转载自www.cnblogs.com/zhouwanchun/p/10954484.html
今日推荐