安装mysql

1、官方定义的MySQL-DBA工作职责
database administrator
开发DBA :
懂至少一门开发语言 :JAVA、Python
基本SQL语句深入学习(增删改查)、数据库结构设计(建模)
高级SQL:存储过程、函数、触发器、视图、事务
运维DBA :
初级:各版本、各平台安装搭建、升级、基础sql语句
中级:体系结构原理、基础管理(启动关闭、初始化配置文件管理、多实例管理、用户权限管理、基本SQL(增删改查))、日志管理、备份与恢复、主从复制(构建、状态监控)
高级:高可用(MGR、InnoDB Cluster)、高性能(优化)
职业要求
熟悉操作系统:主流系统(Linux)
熟悉业务(开发):产品功能、用户行为触发数据库
熟悉行业:熟悉行业发展、版本
常见产品 https://db-engines.com/en/ranking
热爱数据库职业:
严谨:细心 责任心 生产环境修改参数需要经验和理论支持

1、什么是数据?
数据:文字、图片、视频。。。人类认知的数据表现方式
计算机:二进制、16进制的机器语言
基于数据的重要性和复杂性的不同,我们可能有不同的管理方式。
哪些数据是适合存储到数据库的呢?
重要性比较高的
关系较复杂的数据
2、什么是数据库管理系统(DBMS)?
RDBMS: 关系型数据库管理系统
比较适合于,安全级别要求高的数据以及关系较复杂的数据
NoSQL:非关系型数据库管理系统
适合于高性能存取数据,一般是配合RDBMS进行使用的
针对大数据处理分析,分布式架构更加擅长
3、数据库管理系统种类
RDBMS(关系型数据库管理系统):
MySQL 、Oracle、MSSQL(SQL Server)、Postgresql、IBM db2
达梦(oracle9) 人大金仓(pgsql) opengauss oceanbase tidb
NoSQL:Not Only SQL
键-值(key-value):Redis, memcached
文档(document):Mongodb
搜索引擎: Elasticsearch
NewSQL: 分布式数据库:spanner(google)、 tidb 、 polardb(淘宝下一代)

MySQL版本企业选择
1 、规范
GA版本:稳定的发布版本
2 、版本类型
E:企业版,收费版本,SR,偏传统行业
C:社区版,开源版本,互联网企业的选择
3 、企业版本选择
一般新上的环境,会选择GA6-12月版本
4 、企业主流版本***
5.6版本:5.6.34 5.6.36 5.6.38(Sep 13, 2017) 5.6.40
5.7版本:5.7.20(Sep 13, 2017) 5.7.22 5.7.24 5.7.32
8.0版本:8.0.26 (Jul 1, 2021)
注意:面试别说错版本
5 、MySQL分支
Oracle MySQL
MariaDB
PerconaDB
RDS (阿里)
6 、软件下载
地址:https://downloads.mysql.com/archives/community
RPM包: YUM
二进制包:(上课使用的版本)
源码包:C++的源码,需要二次开发的时候,需要做统一配置管理的时候(make&&make install)

安装和基本配置
下载和上传软件到/usr/src
1、 解压
[root@mysql ~]# tar xf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz -C /usr/local
[root@mysql ~]# cd /usr/local
[root@mysql local]# mv mysql-5.7.20-linux-glibc2.12-x86_64/ mysql
修改环境变量及生效
vim /etc/profile
export PATH=/usr/local/mysql/bin:$PATH
[root@mysql local]# source /etc/profile
[root@mysql local]# mysql -V
mysql Ver 14.14 Distrib 5.7.20, for linux-glibc2.12 (x86_64) using EditLine wrapper
3 、清理历史软件包
yum remove -y mariadb-libs
4 、建用户
useradd -s /sbin/nologin mysql
5 、创建数据目录
mkdir -p /usr/local/mysql/data
6、 修改权限
chown -R mysql.mysql /usr/local/mysql/data
7 、初始化数据
5.6 版本的初始化程序: /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data 5.7 版本的初始化程序:
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
–initialize-insecure :加上则可以自定义密码,不加密码必须12位
–initialize参数解释:
初始化完成后,会生成临时密码(显示到屏幕上,并且会往日志中记一份)
密码复杂度:长度:超过12位 复杂度:字符混乱组合
密码过期时间180天
准备启动脚本和基础配置文件
1 准备sys-v启动脚本
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
2 准备配置文件
vim /etc/my.cnf
[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock //卡扣
server_id=6
port=3306
[mysql]
socket=/tmp/mysql.sock
prompt=mysql>
3 、启动数据库
service mysqld start
service mysqld stop
4 systemctl管理数据库
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=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
[root@mysql local]# systemctl restart mysqld
连接数据库
直接输入mysql就可以登录
设置root的初始密码(三种方法)
mysql_secure_installation
mysqladmin -uroot -p password 123
grant all on . to root@localhost identified by ‘123’;
oot@mysql local]# 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 local]# mysql -u root -p
Enter password:

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql>
忘记数据库密码,破解 :
systemctl stop mysqld
mysqld_safe --skip-grant-tables & #跳过权限表,以安全模式启动mysql
root@mysql local]# systemctl stop mysqld
[root@mysql local]# mysqld_safe --skip-grant-tables &
[1] 4874
[root@mysql local]# 2024-11-09T11:44:59.188187Z mysqld_safe Logging to ‘/usr/local/mysql/data/mysql.err’.
2024-11-09T11:44:59.218135Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
mysql
grant all on . to root@localhost identified by ‘123456’; #会报错
flush privileges;
grant all on . to root@localhost identified by ‘123456’;
exit
[root@mysql local]# jobs
[1]+ 运行中 mysqld_safe --skip-grant-tables &
[root@mysql local]# jobs
[1]+ 运行中 mysqld_safe --skip-grant-tables &
[root@mysql local]# killall -9 mysqld_safe
[1]+ 已杀死 mysqld_safe --skip-grant-tables
[root@mysql local]# systemctl start mysqld
[root@mysql local]# mysql -u root -p
Enter password: //密码是123456
Welcome to the MySQL monitor. Commands end with ; or \g.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值