Mysql编译安装和yum安装

一、msql数据库介绍

1、什么是sql

sql代表结构化查询语言,sql是用于访问数据库的标椎化语言

sql包含三个部分

 DDL数据定义语言包含定义数据库及其对象的语言,例如表,视图,触发器,存储过程等

DML数据操作语言包含允许数据更新和查询数据的语句(这里的查询语言可以分为 DQL)

DCL 数据控制语言允许授予用户权限访问数据库中的特定数据;

2.mysql是什么?

mysql是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于Oracle旗下,mysql是最流行的关系型的数据库之一,在web应用方面,MySQL是最好的RDBMS应用软件之一,关系数据库将数据保存在不同的表中,而不是将数据放在一个大仓库,这样就增加了速度并提高数据的灵活性。

MySQL的官方网址: MySQL ,MySQL的社区版本下载地址为: MySQL :: Download MySQL Community Server

3.关系型数据库和非关系型数据库

关系型数据库

基本概念:关系型数据库依据关系模型来创建数据库。

   所谓关系模型就是一对一,一对多,多对多的关系模型,关系模型就是指二维数据表格模     型,因而一个关系型数据库就是由二维表及其之间的联系组成的一个数据组织。

优点:

1.易于维护:使用的都是表结构,格式一致

2.使用方便:sql语言通用,可用于复杂查询

3.复杂操作:支持sql,可用于一个表以及多个表之间非常复杂的查询

4.学习成本低。

缺点:

1.读写性能差,尤其是海量数据高效率读写

2.固定的表结构,灵活度欠缺

3.高并发读写需求,传统关系型数据库来说,硬盘I/O是一个很大的瓶颈

关系型数据库:Oralce Mysql DB2 PostgreSQL SqlServer

非关系型数据库

基本概念:非关系型数据库主要是基于“非关系模型”的数据库(由于关系型太大,所以一般用“非关系型”来表示其他类型的数据库)

优点:

1.格式灵活,存储数据的格式可以是key,value形式,文档形式,图片形式等等

2.速度快:可以使用硬盘或者内存作为载体,而关系型数据只能使用硬盘

3.成本低:数据库部署简单,基本都是开源软件

缺点

1.不提供sql支持,学习和使用成本高;

2.无事务处理

 非关系型数据库:Redis MongDB Memcache

二、yum部署安装MySQL

1.关闭防火墙和selinux

[root@localhost ~]#systemctl stop firewalld && setenforce 0

2.找yum源的rpm安装包

复制链接

3.下载yum源的rpm安装包

[root@localhost ~]# yum install -y https://dev.mysql.com/get/mysql80-community-release-el7-10.noarch.rpm

4.把安装5.7的源打开,关闭安装8.0的源

方法一:(永久关闭)

[root@localhost ~]# vim /etc/yum.repos.d/mysql-community.repo #打开配置文件
# Enable to use MySQL 5.7
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch
enabled=1        #将0改为1,代表打开这个源
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022
       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch
enabled=0        #将1改为0,代表关闭这个源
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022
       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

方法二:(永久关闭)

[root@localhost ~]# yum -y install yum-utils
[root@localhost ~]# yum repolist |grep mysql
mysql-connectors-community/x86_64       MySQL Connectors Community           227
mysql-tools-community/x86_64            MySQL Tools Community                100
mysql80-community/x86_64                MySQL 8.0 Community Server           426
[root@localhost ~]# yum-config-manager --disable mysql80-community
[root@localhost ~]# yum-config-manager --enable mysql57-community

方法三:(临时关闭)

[root@localhost ~]#yum install -y mysql-community-server --enablerepo mysql57-community --disablerepo mysql80-community

5.安装mysql必要安装包

[root@localhost ~]# yum -y install mysql-community-server
[root@localhost ~]# yum -y groupinstall "Development Tools"

6.启动mysql

[root@localhost ~]# systemctl start  mysqld

8.从日志中过滤初始密码

[root@localhost ~]# grep "password" /var/log/mysqld.log
2023-09-25T13:06:14.510313Z 1 [Note] A temporary password is generated for root@localhost: Qo9b-0AXzdIt

9.登录数据库

[root@localhost ~]# mysql -p"Qo9b-0AXzdIt"  #用日志中的密码登录
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 2
Server version: 5.7.43

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

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> 

10.更改mysql密码

 (1)命令行修改密码

[root@localhost ~]# mysqladmin -p"Qo9b-0AXzdIt" password "123" #-p与旧密码之间没有空格,新密码与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.
mysqladmin: unable to change password; error: 'Your password does not satisfy the current policy requirements'  #密码强度不够

[root@localhost ~]# vim /etc/my.cnf #修改配置文件
validate-password=OFF #关闭mysql密码强度策略,生产环境切勿尝试,首次启动不可关闭
[root@localhost ~]# systemctl restart mysqld  #重启mysql
[root@localhost ~]# mysqladmin -p"Qo9b-0AXzdIt" password "123" #再次修改密码
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.

(2)mysql里面修改密码

[root@localhost ~]# mysql -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 4
Server version: 5.7.43 MySQL Community Server (GPL)

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

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> alter user 'root'@'localhost' identified by "123";

 扩展:

MySQL忘记密码后登录并重新设置密码_火腿炒馕的博客-CSDN博客

三、源码编译安装mysql

1.安装mysql的依赖包

[root@mysql_source ~]# yum -y groupinstall "Development Tools"
[root@mysql_source ~]# yum -y install ncurses ncurses-devel openssl-devel bison libgcrypt gcc gcc-c++ make cmake

2.下载mysql的压缩包

 [root@mysql_source ~]wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.24.tar.gz

3.在系统中添加运行mysqld的用户,自定义的数据库目录及其他目录

[root@mysql_source ~]# groupadd mysql
[root@mysql_source ~]# useradd -M -g mysql -s /sbin/nologin mysql
[root@mysql_source ~]# mkdir -p /usr/local/{data,mysql,log,tmp}
[root@mysql_source ~]# chown -R mysql:mysql /usr/local/{data,mysql,log,tmp}

4.解压并自动化构建系统文件

[root@mysql_source ~]# tar xf mysql-boost-5.7.24.tar.gz
[root@mysql_source ~]# cd mysql-5.7.24
[root@mysql_source mysql-5.7.24]# cmake . \
-DWITH_BOOST=boost/boost_1_59_0/ \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DSYSCONFDIR=/etc \
-DMYSQL_DATADIR=/usr/local/data \
-DINSTALL_MANDIR=/usr/share/man \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/usr/local/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_SSL=system \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1

参数解释:

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \   安装目录
-DSYSCONFDIR=/etc \   配置文件存放 (默认可以不安装配置文件)
-DMYSQL_DATADIR=/usr/local/mysql/data \   数据目录   错误日志文件也会在这个目录
-DINSTALL_MANDIR=/usr/share/man \     帮助文档 
-DMYSQL_TCP_PORT=3306 \     默认端口
-DMYSQL_UNIX_ADDR=/usr/local/tmp/mysql.sock \  sock文件位置,用来做网络通信的,客户端连接服务器的时候用
-DDEFAULT_CHARSET=utf8 \    默认字符集。字符集的支持,可以调
-DEXTRA_CHARSETS=all \   扩展的字符集支持所有的
-DDEFAULT_COLLATION=utf8_general_ci \  支持的
-DWITH_READLINE=1 \    上下翻历史命令
-DWITH_SSL=system \    使用私钥和证书登陆(公钥)  可以加密。 适用与长连接。坏处:速度慢
-DWITH_EMBEDDED_SERVER=1 \   嵌入式数据库
-DENABLED_LOCAL_INFILE=1 \    从本地倒入数据,不是备份和恢复。
-DWITH_INNOBASE_STORAGE_ENGINE=1  默认的存储引擎,支持外键

5.编译安装

[root@mysql_source mysql-5.7.24]# make -j 3  #-j 指定cpu的个数,lscpu查看CPU个数
[root@mysql_source mysql-5.7.24]# echo $?    #测试上一步是否正确
0
[root@mysql_source mysql-5.7.24]# make install  #安装

6.初始化MySQL

    (1)提升mysql命令为系统级别命令

[root@mysql_source ~]# echo 'export PATH=$PATH:/usr/local/mysql/bin'>>/etc/profile
[root@mysql_source ~]# source /etc/profile  #重新加载系统环境变量文件/etc/profile,以便使修改后的环境变量生效

      (2)拷贝默认文件至/etc/my.cnf中

[root@mysql_source mysql]# chown -R mysql.mysql /usr/local/mysql #修改属主和属组
[root@mysql_source ~]# cd /usr/local/mysql/mysql-test/include 
[root@mysql_source include]# cp /etc/{my.cnf,my.cnf.bak}  #拷贝文件
[root@mysql_source include]# vim /etc/my.cnf  #修改配置文件
[mysqld]
basedir = /usr/local/mysql                    #安装目录
datadir = /usr/local/data					 #数据存放目录
tmpdir = /usr/local/tmp						 #/tmp缓存目录
socket = /usr/local/tmp/mysql.sock			 #指定socket文件的位置
pid_file = /usr/local/tmp/mysqld.pid			 #指定pid文件的位置
log_error = /usr/local/log/mysql_error.log	 #错误日志的位置
slow_query_log_file = /usr/local/log/slow_warn.log  #慢日志查询

server_id = 1						#server-id=??
user = mysql						#指定用户
port = 3306							#指定端口
bind-address = 0.0.0.0				#监听地址(允许所以ip访问)
character-set-server = utf8			#字符集
default_storage_engine = InnoDB		#引擎

   (3)执行数据库服务初始化操作

[root@mysql_source ~]# cd /usr/local/mysql
[root@mysql-server mysql]# mysqld --defaults-file=/etc/my.cnf --initialize --user='mysql' 
     (4)启动mysqld服务
[root@mysql_source mysql]# mysqld_safe --defaults-file=/etc/my.cnf & #启动进程并把它挂在后台运行
[1] 25705
2019-8-18T09:19:35.334751Z mysqld_safe Logging to '/usr/local/log/mysql_error.log'.
2019-8-18T09:19:35.379829Z mysqld_safe Starting mysqld daemon with databases from /usr/local/data

   (5)配置mysqld的服务管理工具(便与启动)

[root@mysql_source mysql]# cd /usr/local/mysql/support-files
[root@mysql_source support-files]# cp mysql.server /etc/init.d/mysqld #拷贝启动脚本到/etc/init.d/目录下,并改名mysqld
[root@mysql_source support-files]# systemctl daemon-reload #重新加载系统服务
[root@mysql_source support-files]# pkill mysqld  #关闭之前启动的mysql
[root@mysql_source support-files]# systemctl start mysqld #用systemctl的方式启动mysqld
[root@mysql_source support-files]# systemctl enable mysqld #设置开机自启动

7.登录mysql

[root@mysql_source mysql]# grep "password" /usr/local/log/mysql_error.log   #过滤数据库的初始密码
2019-8-18T09:18:34.214401Z 1 [Note] A temporary password is generated for root@localhost: ejhszb2:m3wJ
[root@localhost ~]#mysql  -p"ejhszb2:m3wJ" #登录mysql 
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 2
Server version: 5.7.24 Source distribution

Copyright (c) 2000, 2018, 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> alter user 'root'@'localhost' identified by "123"; #更改密码,方法一
Query OK, 0 rows affected (0.00 sec)

更改密码 方法二:
[root@mysql_source ~]# mysqladmin -p'old_passwd' password "new_passwd"

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是 MySQL 8 的编译安装步骤: 1. 首先需要安装一些依赖包: ``` yum install -y gcc gcc-c++ ncurses ncurses-devel cmake make bison autoconf ``` 2. 下载 MySQL 8 的源码包: ``` wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.26.tar.gz ``` 3. 解压源码包并进入解压后的目录: ``` tar -zxvf mysql-8.0.26.tar.gz cd mysql-8.0.26 ``` 4. 创建一个 build 目录并进入该目录: ``` mkdir build cd build ``` 5. 执行 cmake 命令进行编译前的配置: ``` cmake .. \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DSYSCONFDIR=/etc \ -DWITH_BOOST=boost \ -DWITH_INNODB_MEMCACHED=ON \ -DWITH_SSL=system \ -DWITH_ZLIB=system \ -DENABLED_LOCAL_INFILE=1 \ -DENABLE_DOWNLOADS=1 \ -DWITH_DEBUG=OFF \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_FEDERATED_STORAGE_ENGINE=1 \ -DWITH_ROCKSDB=OFF \ -DWITH_UNIT_TESTS=OFF \ -DDEFAULT_CHARSET=utf8mb4 \ -DDEFAULT_COLLATION=utf8mb4_general_ci \ -DWITH_EXTRA_CHARSETS=all ``` 注意:如果需要使用 RocksDB 存储引擎,则将 -DWITH_ROCKSDB=OFF 改为 -DWITH_ROCKSDB=ON。 6. 执行 make 命令进行编译: ``` make -j $(nproc) ``` 7. 执行 make install 命令进行安装: ``` make install ``` 8. 配置环境变量: ``` echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile source /etc/profile ``` 9. 初始化数据库: ``` cd /usr/local/mysql bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data ``` 10. 启动 MySQL 服务: ``` bin/mysqld_safe --user=mysql & ``` 至此,MySQL 8 的编译安装就完成了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值