CentOS7.x安装MySQL5.7.25
mysql 5.7下载地址
社区版下载地址:https://dev.mysql.com/downloads/mysql/ 可能会有变动
找到5.7版本,
注:源码安装需要用到下面的包,可以先忽略,我安装是提示用到的不是这个版本的包,而且无法解压此包,安装提示中用到的是此包boost_1_59_0.tar.gz,可以连接外网的的情况下,能自动下载安装,没有也不要担心,会在报错页面,给出下载url地址,可以下载后本地上传至服务器中。
或者通过wget下载
wget http://downloads.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.12.tar.gz
环境准备
# cat /etc/centos-release
CentOS Linux release 7.6.1810 (Core)
# uname -r
3.10.0-957.el7.x86_64
# getenforce
Disabled
# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
编译MySQL
解决依赖关系
# yum -y install autoconf automake libtool cmake ncurses-devel openssl-devel lzo-devel zlib-devel gcc gcc-c++ bison bison-devel git libaio-devel
注:下面所有的名利都要用绝对路径避免出错。
创建用户MySQL启动用户
groupadd mysql
useradd -r -g mysql -s /bin/false -M mysql
解压MySQL压缩包
# tar xf mysql-5.7.25
# cd mysql-5.7.25
进入解压目录并将boost_1_59_0.tar.gz放入mysql-5.7.25
# 创建文件目录
mkdir -p /application/mysql-5.7.25
编译安装MySQL
cmake -DCMAKE_INSTALL_PREFIX=/application/mysql-5.7.25/ -DSYSCONFDIR=/application/mysql-5.7.25/ -DMYSQL_DATADIR=/application/mysql-5.7.25/mysqldata -DMYSQL_UNIX_ADDR=/application/mysql-5.7.25/mysql.sock -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=.
-DCMAKE_INSTALL_PREFIX=/application/mysql-5.7.25/ #安装位置
-DSYSCONFDIR=/application/mysql-5.7.25/ #配置文件(my.cnf)目录
-DMYSQL_DATADIR=/application/mysqlData #数据存储目录
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock #mysql.sock目录
-DMYSQL_TCP_PORT=3306 #服务端口
-DMYSQL_USER=mysql #运行用户
-DEXTRA_CHARSETS=all #扩展字符支持
-DDEFAULT_CHARSET=utf8 #默认字符集
-DDEFAULT_COLLATION=utf8_general_ci #默认字符校对
-DWITH_READLINE=1 #readline库
-DENABLED_LOCAL_INFILE=1 #启用加载本地数据
-DWITH_MYISAM_STORAGE_ENGINE=1 #使用Myisam存储引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1 #使用INNOBASE存储引擎
-DWITH_PARTITION_STORAGE_ENGINE=1 #安装数据库分区
-DWITH_MEMORY_STORAGE_ENGINE=1 #安装memory存储引擎
-DDOWNLOAD_BOOST=1 #下载升压文件boost_1_59_0.tar.gz
-DWITH_BOOST=. #指定boots文件位置,点表示当前位置,也可以用绝对路径,开始时因为将文件上传至此目录内,所以用点指定即可。
注:注意磁盘空间,不满足的情况下也是会编译失败的,最少给MySQL准备10G空间。
# make && make install
复制启动程序
cp support-files/mysql.server /etc/init.d/mysqld
注:centos7中,init.d下的启动文件要配置755权限,才可以使用,安装包中含有systemctl启动文件,可以用systemctl管理MySQL。
注:mysql。sock文件存放位置要设置成mysql:mysql用户,不然会提示没有sock文件。
设置mysql环境变量:
# echo "export PATH=/application/mysql/bin:/application/mysql/lib:$PATH" >>/root/.bash_profile
# source /root/.bash_profile
修改mysql权限
# chown -R mysql:mysql /application/*
创建软连接,MySQL升级后可以指定新的目录
# ln -s # ln -s /application/mysql-5.7.25 /application/mysql
配置my.cnf
# vim /etc/my.cnf
[client]
port = 3306
socket = /var/lib/mysql/mysql.sock
default-character-set = utf8
[mysqld]
port = 3306
socket = /var/lib/mysql/mysql.sock
basedir = /application/mysql
datadir = /application/mysqlDate
pid-file = /application/mysqlDate/mysql.pid
user = mysql
bind-address = 0.0.0.0
server-id = 1
init-connect = 'SET NAMES utf8mb4'
character-set-server = utf8mb4
skip-name-resolve
#skip-networking
back_log = 300
max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 4M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 4M
thread_cache_size = 8
query_cache_type = 1
query_cache_size = 8M
query_cache_limit = 2M
ft_min_word_len = 4
log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 30
log_error = /application/mysqlDate/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /application/mysqlDate/mysql-slow.log
performance_schema = 0
explicit_defaults_for_timestamp
#lower_case_table_names = 1
skip-external-locking
default_storage_engine = InnoDB
#default-storage-engine = MyISAM
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 64M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 28800
[mysqldump]
quick
max_allowed_packet = 16M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
启动MySQL
# /etc/init.d/mysqld restart
# ps -ef |grep mysql
root 11478 1 0 14:13 pts/0 00:00:00 /bin/sh /application/mysql/bin/mysqld_safe --datadir=/application/mysqlDate --pid-file=/application/mysqlDate/mysql.pid
mysql 12320 11478 8 14:13 pts/0 00:00:00 /application/mysql/bin/mysqld --basedir=/application/mysql --datadir=/application/mysqlDate --plugin-dir=/application/mysql/lib/plugin --user=mysql --log-error=/application/mysqlDate/mysql-error.log --open-files-limit=65535 --pid-file=/application/mysqlDate/mysql.pid --socket=/var/lib/mysql/mysql.sock --port=3306
# netstat -antup|grep mysql
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 12320/mysqld
MySQL初始化
# MySQL5.7已经不推荐使用mysql_install_db初始化数据库了
进行一些安全设置,以及修改数据库管理员密码
# /application/mysql/bin/mysql_sceure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
注意:建议对所有Mariadb运行此脚本的所有部分生产中使用的服务器!请仔细阅读每一步!
In order to log into MariaDB to secure it, we'll need the currentpassword for the root user. If you've just installed MariaDB, andyou haven't set the root password yet, the password will be blank,so you should just press enter here.
Enter current password for root (enter for none): 回车即可
OK, successfully used password, moving on...
为了登录Mariadb以保护它,我们需要MariaDB根用户的密码。如果你刚刚安装了Mariadb,您尚未设置根密码,密码将为空,所以你只需在这里按回车键。
Setting the root password ensures that nobody can log into the MariaDBroot user without the proper authorisation.
Set root password? [Y/n]
设置根密码确保没有人可以登录mariadb未经适当授权的根用户。设置根密码?[y/n] #这里选择y,如果出现报错说明你没有用绝对路径,所有命令都是运行在据对路径下的,可以通过配置PATH来使命令生效。
By default, a MariaDB installation has an anonymous user, allowing anyoneto log into MariaDB without having to have a user account created forthem. This is intended only for testing, and to make the installationgo a bit smoother. You should remove them before moving into aproduction environment.
Remove anonymous users? [Y/n]
默认情况下,Mariadb安装有匿名用户,允许任何人登录Mariadb而不必为其创建用户帐户他们。仅用于测试和安装稍微平稳一点。在移动到生产环境。
删除匿名用户?[y/n] #这里y清除匿名用户。
Normally, root should only be allowed to connect from 'localhost'. Thisensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n]
通常,只允许根目录从“localhost”连接。这个确保有人无法猜测网络中的根密码。
不允许远程登录根目录?[y/n] # 这里选择y
By default, MariaDB comes with a database named 'test' that anyone canaccess. This is also intended only for testing, and should be removedbefore moving into a production environment.
Remove test database and access to it? [Y/n]
默认情况下,Mariadb附带一个名为“test”的数据库,任何人都可以访问该数据库。这也仅用于测试,在进入生产环境之前应将其移除。
删除测试数据库并访问它?[y/n] #这里选y
Reloading the privilege tables will ensure that all changes made so farwill take effect immediately.
Reload privilege tables now? [Y/n]、
重新加载特权表将确保所做的所有更改立即生效。
现在重新加载特权表?[y/n] #这里选择y
此时初始化及安全初始化就算做完了。
MySQL密码更改方法:
# ./mysqladmin -uroot -p password #enter
第一次输入原密码
第二次输入新密码
第三次验证新密码
登录进MySQL后输入下面命令
修改mysql的用户密码,分别使用grant、alter、set修改
l grant all on *.* to '用户名'@'登录主机' identified by '密码';
l alter user '用户名'@'登录主机' identified by '密码(自定义)';
l set password for 'root'@'localhost' = password('new password');
#所有修改密码操作,完成后都需要执行下边的命令
flush privileges;
忘记密码修改方法:
l 修改 /etc/my.cnf,在 [mysqld] 小节下添加一行:skip-grant-tables=1
l 这一行配置让 mysqld 启动时不对密码进行验证
l 重启 mysqld 服务:systemctl restart mysqld
l 使用 root 用户登录到 mysql:mysql -u root
l 切换到mysql数据库,更新 user 表:
l update user set authentication_string = password('root'), password_expired = 'N', password_last_changed = now() where user = 'root';
l 在之前的版本中,密码字段的字段名是 password,5.7版本改为了 authentication_string
l 退出 mysql,(exit或者quit)编辑 /etc/my.cnf 文件,删除 skip-grant-tables=1 的内容
l 重启 mysqld 服务,再用新密码登录即可
CentOS7.x安装MySQL5.7.25的更多相关文章
- Centos7二进制文件安装MySQL5.7.25
1.删除centos系统自带的mariadb数据库防止发生冲突 rpm -qa|grep mariadb rpm -e mariadb-libs --nodeps 2.安装libaio库 yum -y ...
- Centos7 yum安装MySQL5.7.25
1 下载并安装MySQL官方的 Yum Repository[root@localhost ~]# wget -i -c http://dev.mysql.com/get/mysql57-commun ...
- 【MySQL】Centos7 yum安装MySQL5.7.25
在CentOS中默认安装有MariaDB,这个是MySQL的分支,但为了需要,还是要在系统中安装MySQL,而且安装完成之后可以直接覆盖掉MariaDB. 安装操作 下载并安装MySQL官方的Yum ...
- Centos7 yum安装 MySQL5.7.25
扩展:在CentOS中默认安装有MariaDB,这个是MySQL的分支,但为了需要,还是要在系统中安装MySQL,而且安装完成之后可以直接覆盖掉MariaDB. 1 下载并安装MySQL官方的 Yum ...
- 在 CentOS7 上安装 MySQL5.7
在 CentOS7 上安装 MySQL5.7 1 通过 SecureCRT 连接到阿里云 CentOS7 服务器: 2 进入到目录 /usr/local/ 中: cd /usr/local/ 3 创建 ...
- CentOS6.3 编译安装LAMP(3):编译安装 MySQL5.5.25
所需源码包: /usr/local/src/MySQL-5.5.25/cmake-2.8.8.tar.gz /usr/local/src/MySQL-5.5.25/mysql-5.5.25.tar.g ...
- centos7编译安装MySQL5.7.9
title: centos7编译安装MySQL5.7.9 date: 2016-05-12 16:20:17 tags: --- Centos7编译安装mysql5.7.9 mysql5.7有更好的性 ...
- [ 原创 ] Centos7.6安装Mysql5.7
https://blog.csdn.net/shj_php/article/details/86712408 CentOS7下安装MySQL5.7安装与配置(YUM) http://blog.csdn ...
- CentOS7 离线安装mysql-5.7.16
CentOS7 离线安装mysql-5.7.16 1 . 安装新版mysql前,需将系统自带的mariadb-lib卸载 [root@slave mytmp]# rpm -qa|grep mariad ...
随机推荐
- 千星项目.Net Core 2.1移植填坑记--OpenAuth.Core诞生
背景 很早就有把OpenAuth.Net----最好用的.net权限管理工作流框架(好吧!我在吹牛
- ubuntu-18.04 安装zsh的方法步骤
zsh是一款跨平台的轻量级的终端,功能十分强大,会极大地提升你的工作效率.安装指南: ➜ ~ sudo apt-get install zsh ➜ ~ zsh --version #确认是否安装成功 ...
- 从壹开始前后端分离 [ Vue2.0+.NET Core2.1] 二十三║Vue实战:Vuex 其实很简单
前言 哈喽大家周五好,马上又是一个周末了,下周就是中秋了,下下周就是国庆啦,这里先祝福大家一个比一个假日嗨皮啦~~转眼我们的专题已经写了第 23 篇了,好几次都坚持不下去想要中断,不过每当看到群里的交 ...
- CollapsingToolbarLayoutDemo【可折叠式标题栏,顺便带有CardView卡片式布局】
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 CollapsingToolBarLayout是一个作用于ToolBar基础之上的布局,它也是由Design Support库提供的 ...
- Linux 中查看进程及资源使用情况
top 自带的 top 命令类似于平时我们使用的任务管理器,能够列出当前系统中的进程及资源的使用情况. $ man top top - display Linux tasks 使用起来很简单,不加任何 ...
- Python3+unitest自动化测试初探(下篇)
目录 9.用例结果校验 10.跳过用例 11.Test Discovery 12.加载用例 unittest官方文档 本篇随笔承接: Python3+unitest自动化测试初探(中篇) Python ...
- vue项目使用MD5进行密码加盐
首先给项目安装MD5模块:npm install --save js-md5 使用方法有两种: 使用方法1: 在需要使用的项目文件中引入MD5:import md5 from 'js-md5'; 使 ...
- Python Ast介绍及应用
Abstract Syntax Trees即抽象语法树.Ast是python源码到字节码的一种中间产物,借助ast模块可以从语法树的角度分析源码结构.此外,我们不仅可以修改和执行语法树,还可以将Sou ...
- vue中用mock制造模拟接口(本文主要解决坑),一定要看完哦
最近新入职一家公司,后端造接口速度很慢,想来想去还是搞一套模拟接口,来满足开发需求,有人会问,我造一个死数据不就可以了吗?或者说,后端数据结构都没出来,字段我怎么定? 问这个问题的人不奇怪,我之前也有 ...
- keil教程之新建软件工程
前言 工欲善其事,必先利其器.要学好52单片机,就要会用keil写程序.不然,谈何学习单片机.下面介绍keil的使用. keil简介 Keil C51是美国Keil Software公司出品的51系列 ...