centos 7 安装 mysql(源码安装)

安装步骤

先删除centos7 自带的 mariadb ,否则会产生冲突!

先删除centos7 自带的 mariadb ,否则会产生冲突!

先删除centos7 自带的 mariadb ,否则会产生冲突!

rpm -qa | grep mariadb

rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64

打开防火墙端口和关闭selinux

firewall-cmd --zone=public --add-port=3306/tcp --permanent

setenforce 0

1.安装依赖包

yum install -y  gcc gcc-c++ cmake ncurses ncurses-devel bison

yum install -y bison bzip2 git hostname ncurses-devel

yum -y install openssl-devel

yum -y install *libtirpc*

yum -y install centos-release-scl

yum -y install devtoolset-8-gcc*

2.下载相应源码包(找了个别人的图)
mysql8 编译安装需要boost 库,这里官网下载含boost的源码包

3.添加用户

useradd -s /sbin/nologin mysql

4.建立所需目录并更改所有者为mysql

mkdir -p /usr/local/mysql/data  
chown -R mysql:mysql /usr/local/mysql

5.将下载好的mysql 解压到/usr/local/mysql 目录下

cd /usr/local/mysql

tar -zxvf mysql-boost-8.0.21.tar.gz -C .

 6.切换到解压后的 mysql-8.0.21 目录下,编译安装

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_BOOST=boost \
-DFORCE_INSOURCE_BUILD=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data

配置参数说明:

CMAKE_INSTALL_PREFIX :指定基础安装目录
MYSQL_DATADIR :指定数据目录
SYSCONFDIR=/etc :指定配置文件目录
MYSQL_TCP_PORT :指定端口号
WITH_BOOST :指定boost所在目录
DEFAULT_CHARSET :指定默认字符集
DEFAULT_COLLATION :指定默认排序规则
ENABLED_LOCAL_INFILE=ON :是否为load data infile启用local
WITH_INNODB_MEMCACHED=ON :是否生成memcached共享库
FORCE_INSOURCE_BUILD: 不要构建源代码

这步有可能会遇到了超多问题,网上基本都有,自己去查,相信你能行的,耐心点就好

其中我觉得最难的是那个 GCC 5.3 or newer is required (-dumpversion says 4.8.5) ,找了很久很久才找到,问题解决  mysql 编译安装 GCC 5.3 or newer is required (-dumpversion says 4.8.5)_羽之大公公的博客-CSDN博客

8.安装

make && make install

9.安装好后的/usr/local/mysql 目录结构

 10.编辑/etc/my.cnf ( 如果没有则创建),我这边的一个配置文件内容如下

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove the leading "# " to disable binary logging
# Binary logging captures changes between backups and is enabled by
# default. It's default setting is log_bin=binlog
# disable_log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
#
# Remove leading # to revert to previous value for default_authentication_plugin,
# this will increase compatibility with older clients. For background, see:
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
# default-authentication-plugin=mysql_native_password

[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=/usr
# 设置mysql数据库的数据的存放目录
datadir=/var/lib/mysql
# 允许最大连接数
max_connections=200
# 允许连接失败的次数。
max_connect_errors=10
# 服务端使用的字符集默认为utf8mb4
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用“mysql_native_password”插件认证
#mysql_native_password
default_authentication_plugin=mysql_native_password
#导出限制
secure-file-priv=""
#事件开启
event_scheduler=on

lower_case_table_names = 1

#二进制
log_bin=/var/log/mysql/binlog
binlog_expire_logs_seconds = 4860000
max_binlog_size = 100M

binlog_format=statement

#通用日志
general_log=1
general_log_file=/var/log/mysql/pc.log

#慢查询日志
slow_query_log = on
slow_query_log_file=/var/log/mysql/slow.log
long_query_time = 300

log_queries_not_using_indexes = on


socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysql/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

#跳过外部锁定
skip-external-locking

#innodb_buffer_pool_size = 128M
#innodb_log_file_size = 32M
#innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1

#key_buffer_size = 32M
#max_allowed_packet = 1024M
#sort_buffer_size = 8M
#read_buffer_size = 768K
#read_rnd_buffer_size = 512K

 
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8mb4
 
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
#default-character-set=utf8mb4

9.把安装目录用户和组更改为mysql

chown -R mysql:mysql mysql 

10.进入 bin目录 ,初始化数据库

./mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

11.拷贝可执行配置文件

1.cd support-files

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

 12.启动服务

service mysqld start

在这里插入图片描述

13. 测试连接,因为配置文件中有  skip-grant-tables,所以无需密码即可成功

./mysql -hlocalhost -uroot -p

14.设定新密码

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '密码';

15.将配置文件里的  skip-grant-tables 删除,重新打开mysql服务

service mysqld stop

service mysqld start

16.建立软连接

 ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql

17.设置开机启动

systemctl enable mysqld

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值