MYSQL部署安装
1.什么是数据?
数据:文字、图片、视频。。。人类认知的数据表现方式
计算机:二进制、16进制的机器语言
基于数据的重要性和复杂性的不同,我们可能有不同的管理方式。
哪些数据是适合存储到数据库的呢?
重要性比较高的
关系较复杂的数据
2.什么是数据库管理系统(DBMS)?
RDBMS: 关系型数据库管理系统
比较适合于,安全级别要求高的数据以及关系较复杂的数据
NoSQL:非关系型数据库管理系统
适合于高性能存取数据,一般是配合RDBMS进行使用的
针对大数据处理分析,分布式架构更加擅长
3.数据库管理系统种类
RDBMS :
MySQL 、Oracle、MSSQL(SQL Server)、PG
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 版本选择建议要上新环境
1.一般选择官方主流版本:5.6,5.7
2.GA(稳定发布版)
3.6-12月的产品版本
4.4 如何获取MySQL软件
企业版:Enterprise , 互联网行业一般不选择.
社区版本:选择
源码包:source code .tar.gz
通用二进制
面试题:
你们公司用什么版本数据库? 具体什么小版本号?
5.6.20 5.6.34 5.6.36 5.6.38 5.6.40
5.7.18 5.7.20 5.7.22
#mysql官网地址
https://www.mysql.com/
5. 下载mysql二进制包
https://downloads.mysql.com/archives/community/
6. 创建存放安装包目录
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
mkdir -p /data/{app,data_mysql,log}
tar xf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz -C /data/app/
cd /data/app
ln -s mysql-5.7.28-linux-glibc2.12-x86_64/ mysql
7. 创建mysql用户
useradd mysql
8. 修改环境变量
vim /etc/profile
#在最后面添加
export PATH=/data/app/mysql/bin:$PATH
source /etc/profile
8.1 测试环境变量是否配置成功
[root@db01 ~]# mysql -V
mysql Ver 14.14 Distrib 5.7.28, for linux-glibc2.12 (x86_64) using EditLine wrapper
9. 权限修改
~]# chown -R mysql.mysql /data
10. 清理mariadb包
~]# rpm -qa | grep mariadb
mariadb-libs-5.5.64-1.el7.x86_64
~]# yum -y remove mariadb-libs-5.5.64-1.el7.x86_64
11. 初始化数据
#5.7初始化方式
--user= #启动用户
--basedir= #安装目录
--datadir= #数据存放目录
#两种方式
(1).mysqld --initialize
1.初始化完成后,会有12位临时密码,但是必须在mysql之前重置这个密码
[Note] A temporary password is generated for root@localhost: dospTe,ga2K<
2.密码使用严格模式:3中密码复杂度
(2).mysqld --initialize-insecure
#5.6初始化方式
/data/app/mysql/scripts/mysql_install_db --user=mysql --datadir=/data/app/mysql/ --basedir=/data/data_mysql
11.1 方式一
[root@db01 data]# mysqld --initialize --user=mysql --basedir=/data/app/mysql --datadir=/data/data_mysql
2020-09-30T03:30:46.821974Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-09-30T03:30:47.163984Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-09-30T03:30:47.223716Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-09-30T03:30:47.285123Z 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: 546c0e20-02cd-11eb-b089-000c29e65ed3.
2020-09-30T03:30:47.286339Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-09-30T03:30:48.161896Z 0 [Warning] CA certificate ca.pem is self signed.
2020-09-30T03:30:48.546326Z 1 [Note] A temporary password is generated for root@localhost: dospTe,ga2K<
11.1.1 初始化报错
问题1
报错原因: Linux系统中缺少libaio-devel 软件包
#解决方法
yum install -y libaio-devel
问题2
报错原因:
在/data/mysql 存在文件
解决:
\rm -rf /data/data_mysql/*
11.2 方法二
[root@db01 data]# mysqld --initialize-insecure --user=mysql --basedir=/data/app/mysql --datadir=/data/data_mysql
2020-09-30T03:24:20.303873Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-09-30T03:24:20.661677Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-09-30T03:24:20.735250Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-09-30T03:24:20.796434Z 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: 6e0e8ffa-02cc-11eb-a6aa-000c29e65ed3.
2020-09-30T03:24:20.797528Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-09-30T03:24:22.609697Z 0 [Warning] CA certificate ca.pem is self signed.
2020-09-30T03:24:22.704618Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
[root@db01 data]# cd /data/3306/
[root@db01 3306]# ll
total 110660
-rw-r-----. 1 mysql mysql 56 Sep 30 11:24 auto.cnf
-rw-------. 1 mysql mysql 1680 Sep 30 11:24 ca-key.pem
-rw-r--r--. 1 mysql mysql 1112 Sep 30 11:24 ca.pem
-rw-r--r--. 1 mysql mysql 1112 Sep 30 11:24 client-cert.pem
-rw-------. 1 mysql mysql 1680 Sep 30 11:24 client-key.pem
-rw-r-----. 1 mysql mysql 425 Sep 30 11:24 ib_buffer_pool
-rw-r-----. 1 mysql mysql 12582912 Sep 30 11:24 ibdata1
-rw-r-----. 1 mysql mysql 50331648 Sep 30 11:24 ib_logfile0
-rw-r-----. 1 mysql mysql 50331648 Sep 30 11:24 ib_logfile1
drwxr-x---. 2 mysql mysql 4096 Sep 30 11:24 mysql
drwxr-x---. 2 mysql mysql 8192 Sep 30 11:24 performance_schema
-rw-------. 1 mysql mysql 1676 Sep 30 11:24 private_key.pem
-rw-r--r--. 1 mysql mysql 452 Sep 30 11:24 public_key.pem
-rw-r--r--. 1 mysql mysql 1112 Sep 30 11:24 server-cert.pem
-rw-------. 1 mysql mysql 1676 Sep 30 11:24 server-key.pem
drwxr-x---. 2 mysql mysql 8192 Sep 30 11:24 sys
13. 书写默认配置文件
vim /etc/my.cnf
[mysqld]
user=mysql
port=3306
basedir=/data/app/mysql
datadir=/data/data_mysql
socket=/tmp/mysql.sock
[mysql]
socket=/tmp/mysql.sock
14. 使用systemd管理mysql
cp mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
systemctl start mysql
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=/data/app/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
15.测试登录
mysql
16.安装后的简单管理
[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.
5.6版本:
select user,password,host from mysql.user;
5.7 中用户基本信息
select user,authentication_string,host from mysql.user;
desc mysql.user;