zoukankan      html  css  js  c++  java
  • MySQL -1- 简介及安装

    第一章 MySQL 大纲介绍

    1、官方定义的MySQL DBA工作内容

    (1)运维DBA

    初级:各版本、各平台安装搭建、升级

    中级:体系结构原理、基础管理(启动关闭、初始化配置文件管理、多实例管理、用户权限管理、基本SQL(增删改查))、日志管理、备份与恢复、主从复制(构建、状态监控)

    高级:高可用(MGR、InnoDB Cluster)、高性能(优化)

    (2)开发DBA

    懂至少一门开发语言 :JAVA、Python

    基本SQL语句深入学习(增删改查)、数据库结构设计(建模)

    高级SQL:存储过程、函数、触发器、视图、事件

    2、老男孩MySQL课程-2019-03月-中级DBA要求(80%以上)

    (1)MySQL 5.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)MySQL 5.7 高可用及分布式架构-扩展(MGR,InnoDB Cluster)***

    (16)MySQL优化(安全、性能) ****

    (17)MySQL 监控(zabbix、Open-falcon) ****

    (18) RDS(阿里云课程) *****

    额外要会的: Redis、mongodb

    了解: PG 、 Oracle

    3、DBA职业素养

    3.1、人品

    责任-----权利

    3.2

    3.2.1、严谨

    磁带库----->备份软件-----17楼

    数据库修改删除类的命令时 再三考虑,而且要有理论或者实践的支撑

    3.2.2 请收起你的好奇心!!!!!

    注意规范:

    脱库? 华住网(ip root 密码),“脱敏”!!!!!。

    学会保护自己!!!

    3.3、细心

    把最简单的事情做的最漂亮,最专业。

    不要怕成功的门很拥挤,因为很多人在半路就已经放弃了.----郭导

    3.4、心态

    别惹事,出事别怕事。

    ---------------------------

    职业技能有关:

    3.5、熟悉操作系统(精通)

    3.6、熟悉公司业务

    业务?

        产品的功能

        用户的行为(热功能,热数据)

    3.7、熟悉行业

    熟悉行业发展趋势、版本

    数据库产品类型排名情况

    https://db-engines.com/en/ranking

    3.8、喜欢数据库

    体验很重要

    第二章: MySQL 介绍和安装

    1、什么是数据?

    数据:文字、图片、视频。。。人类认知的数据表现方式

    计算机:二进制、16进制的机器语言

    基于数据的重要性和复杂性的不同,我们可能有不同的管理方式。

    哪些数据是适合存储到数据库的呢?

    重要性比较高的

    关系较复杂的数据

    2、什么是数据库管理系统(DBMS)?

    RDBMS: 关系型数据库管理系统

    比较适合于,安全级别要求高的数据以及关系较复杂的数据

    NoSQL:非关系型数据库管理系统

    适合于高性能存取数据,一般是配合RDBMS进行使用的

    针对大数据处理分析,分布式架构更加擅长,可独立使用

    3、数据库管理系统种类

    RDBMS :

    MySQL 、Oracle、MSSQL(SQL Server)、PG(PostGresql)

    NoSQL:Not Only SQL

    键-值(key-value):Redis, memcached

    文档(document):Mongodb

    4、MySQL简介及产品线

    4.1 MySQL行业主流版本:

    5.6

    5.7

    8.0(现在开始研究新特性)

    4.2 企业版本选择(MySQL分支版本),笔试题

    Oracle:

        MySQL官方版

    红帽 :

        MariaDB

    Percona:

        PerconaDB

    4.3 MySQL版本选择建议要上新环境

    1.一般选择官方主流版本:5.6,5.7

    2.GA(稳定发布版)

    3.6-12月的产品版本

    4.4 课程版本:

    5.7.20 二进制安装,其他安装方式自己扩展

    4.5 如何获取MySQL软件

    企业版:Enterprise , 互联网行业一般不选择.

    社区版本:选择

    源码包:source code .tar.gz

    通用二进制

    官方网站:mysql.com

    --DOWNLOADS--Archives--MySQL Community Server

    5.7.20--Linux -Generic --64-bit-Archive--611.4M--download

    5.6.38(也可以)

    面试题:

    你们公司用什么版本数据库? 具体什么小版本号?

    5.6.20 5.6.34 5.6.36 5.6.38 5.6.40

    5.7.18 5.7.20 5.7.22

    5、MySQL二进制安装

    5.1.创建软件目录:

    [root@db01 ~]# mkdir -p /app/

    上传软件到此目录解压

    rz -E 

    tar xvf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz

    5.2. 解压并改名为mysql

    [root@db01 app]# mv mysql-5.7.20-linux-glibc2.12-x86_64 mysql

    [root@db01 app]# ls -l /app/mysql/

    total 36

    drwxr-xr-x  2 root root   4096 Mar  4 14:55 bin

    -rw-r--r--  1 7161 31415 17987 Sep 13  2017 COPYING

    drwxr-xr-x  2 root root     55 Mar  4 14:55 docs

    drwxr-xr-x  3 root root   4096 Mar  4 14:55 include

    drwxr-xr-x  5 root root    229 Mar  4 14:55 lib

    drwxr-xr-x  4 root root     30 Mar  4 14:55 man

    -rw-r--r--  1 7161 31415  2478 Sep 13  2017 README

    drwxr-xr-x 28 root root   4096 Mar  4 14:55 share

    drwxr-xr-x  2 root root     90 Mar  4 14:55 support-files

    修改环境变量:

    vim /etc/profile

    export PATH=/app/mysql/bin:$PATH

    [root@db01 bin]# source /etc/profile

    5.3. 建立mysql用户和组(如果已有可忽略)

    useradd mysql

    groupadd  mysql  (已经存在时可忽略)

    5.4. 创建相关目录并修改权限

    mkdir /data/mysql -p

    chown -R mysql.mysql /app/*

    chown -R mysql.mysql /data/*

    5.5 初始化数据(建库)

    方法一:临时加密安全初始化(不推荐)

    初始化数据,初始化管理员的临时密码

    初始化数据,初始化管理员的临时密码

    mysqld --initialize  --user=mysql --basedir=/app/mysql --datadir=/data/mysql

    2019-04-18T03:21:53.381108Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

    2019-04-18T03:21:54.583415Z 0 [Warning] InnoDB: New log files created, LSN=45790

    2019-04-18T03:21:54.697859Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.

    2019-04-18T03:21:54.760821Z 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: 1daa0c57-6189-11e9-bc80-000c294234c8.

    2019-04-18T03:21:54.770856Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.

    2019-04-18T03:21:54.772016Z 1 [Note] A temporary password is generated for root@localhost: 9LN.fh_Ea#uU

    报错原因: Linux系统中缺少libaio-devel 软件包

    解决:

    yum install -y libaio-devel

    报错原因:

    在/data/mysql 存在文件

    解决:

    m -rf /data/mysql/*

    新特性重要说明:

    5.7开始,MySQL加入了全新的 密码的安全机制:

    1.初始化完成后,会生成临时密码(显示到屏幕上,并且会往日志中记一份)

    2.密码复杂度:长度:超过12位? 复杂度:字符混乱组合

    3.密码过期时间180天

    方法二 :

    初始化数据,初始化管理员的密码为空

    m -rf  /data/mysql/*

    [root@db01 ~]# mysqld --initialize-insecure  --user=mysql --basedir=/app/mysql --datadir=/data/mysql

    2019-04-18T03:37:43.146018Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

    2019-04-18T03:37:43.892132Z 0 [Warning] InnoDB: New log files created, LSN=45790

    2019-04-18T03:37:43.970412Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.

    2019-04-18T03:37:44.029490Z 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: 5378f3b3-618b-11e9-9164-000c294234c8.

    2019-04-18T03:37:44.041469Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.

    2019-04-18T03:37:44.042348Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

    如果是装载了mariadb,先删除

    yum remove mariabd-**

    [root@db01 ~]#

    [root@db01 ~]# cd /data/mysql/

    [root@db01 mysql]# ll

    total 110628

    -rw-r----- 1 mysql mysql       56 Apr 18 11:37 auto.cnf

    -rw-r----- 1 mysql mysql      419 Apr 18 11:37 ib_buffer_pool

    -rw-r----- 1 mysql mysql 12582912 Apr 18 11:37 ibdata1

    -rw-r----- 1 mysql mysql 50331648 Apr 18 11:37 ib_logfile0

    -rw-r----- 1 mysql mysql 50331648 Apr 18 11:37 ib_logfile1

    drwxr-x--- 2 mysql mysql     4096 Apr 18 11:37 mysql

    drwxr-x--- 2 mysql mysql     8192 Apr 18 11:37 performance_schema

    drwxr-x--- 2 mysql mysql     8192 Apr 18 11:37 sys

    [root@db01 mysql]#

    注释:5.6初始化的区别

    /application/mysql/scripts/mysql_install_db  --user=mysql --datadir=/application/mysql/data --basedir=/application/mysql

    5.6 书写默认配置文件

    vim /etc/my.cnf

    [mysqld]

    user=mysql

    basedir=/app/mysql

    datadir=/data/mysql

    server_id=6

    port=3306

    socket=/tmp/mysql.sock

    [mysql]

    socket=/tmp/mysql.sock

    prompt=3306 [\d]>

    5.7 配置启动脚本:

    [root@db01 mysql]# cd /app/mysql/support-files

    [root@db01 support-files]# ./mysql.server start

    Starting MySQL.Logging to '/data/mysql/db01.err'. SUCCESS!

    mysql  --直接登录mysql

    ctrl d 退出

    ./mysql.server stop

    netstat -lnutop|grep 3306--查看端口

    ps -ef|grep 3306

    ss -lnp|grep 3306

    cp mysql.server  /etc/init.d/mysqld

    service mysqld restart 

    5.8 使用systemd管理mysql

    vim /etc/systemd/system/mysqld.service

    [Unit]

    Description=MySQL

    ServerDocumentation=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=/app/mysql/bin/mysqld

    --defaults-file=/etc/my.cnf

    LimitNOFILE = 5000

    注意:将原来模式启动mysqld先关闭,然后再用systemd管理。

    systemctl  start/stop/restart/status   mysqld

    mysql

    show databases;

    use mysql

    6. 安装后的简单管理--改root密码

    [root@db01 ~]# 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.

    再登录时 mysql -uroot -p123

    或mysql -uroot -p

    此处输入密码

    5.6版本:

    select user,password,host from mysql.user;

    5.7 中用户基本信息

    select user,authentication_string,host from mysql.user;

    desc  mysql.user;

    小结:

    1.版本 (主流版本的GA时间了解一下)

    5.6 5.7

    5.6.38 5.7.20

    20170913

    (1) 初始化方式变了

    5.6 版本:mysql_install_db

    5.7版本:mysqld --initialize-insecure

    (2) 用户安全

    5.7   12位,180天,4种复杂度

    (3)密码字段

    authentication_strings,原来是password

    select user,host,authentication_strings from mysql.user;

    2.安装方法:

    二进制、源码、yum

    3.建库(初始化数据库)

    mysqld --intialize-insecure --user=mysql --basedir=/app/mysql --datadir=/data/mysql

    4.简易的配制文件/etc/my.cnf

    user basedirdatadir server_idportsocket

    5.管理员密码

    mysqladmin -uroot -p password xx

    6.登录

    mysql -uroot -p

  • 相关阅读:
    跨表修改数据|查询修改数据|两表联合修改数据
    .net oracle 连接
    型材优化截取初步代码
    JQuery.getJSON 从aspx页面返回JSON数据 .
    asp.net form验证
    ASP.NET读取纯真IP数据库QQWry.Dat,得到地址名称
    防止PHP木马,应在PHP.INI里禁止的一些函数
    sqlserver2005中的数据库日志收缩
    jquery.pagination.js分页插件的运用
    ASP.NET前台代码绑定后台变量方法总结
  • 原文地址:https://www.cnblogs.com/moox/p/11220542.html
Copyright © 2011-2022 走看看