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 ...
随机推荐
- ASP.NET的版本?
问题源于这么一本书: <ASP.NET 4 解密(卷1)>,这本书大约是六七年前买的了,根据其名字,它讲述的是ASP.NET 4,那么ASP.NET现在究竟是什么版本?与.NET Fram ...
- 一分钟上手artTemplate
一分钟上手artTemplate artTemplate是腾讯开源的前端模版引擎.之前做hue二次开发,只接触过用python写的mako模版引擎,所以之前对前端模版引擎了解不是很多. 这次因为pm叫 ...
- Flarum轻量级论坛的安装
论坛作为互联网中的远古产物,经历了如QQ群.社区和贴吧等新兴社交工具的冲击,依然能够存在,肯定是有着不可替代的用处,像吾爱.远景等论坛依旧火热.一些博客主也喜欢自己搭建一个论坛作为用户聚集之地. 之前 ...
- PHP Iterator迭代对象属性
foreach用法和之前的数组遍历是一样的,只不过这里遍历的key是属性名,value是属性值.在类外部遍历时,只能遍历到public属性的,因为其它的都是受保护的,类外部不可见. class Har ...
- Android开发:APK的反编译(获取代码和资源文件)
一.反编译工具: 1.APKTool: APKTool是由GOOGLE提供的APK编译工具,能够完成反编译及回编译apk的工作.同时,它也有着安装反编译系统apk所需要的framework-res框架 ...
- 【Caffe篇】--Caffe从入门到初始及各层介绍
一.前述 Caffe,全称Convolutional Architecture for Fast Feature Embedding.是一种常用的深度学习框架,主要应用在视频.图像处理方面的应用上.c ...
- 『练手』004 Laura.SqlForever如何扩展 导航栏 工具栏 右键菜单 插件
004 Laura.SqlForever如何扩展 导航栏 工具栏 右键菜单 插件 导航栏 插件扩展 比如下图的 窗口 > 关闭所有文档 这个导航栏: 在 任何程序集,任何命名空间,任 ...
- [macOS开发.NET Core] 开篇 & 抉择 & 先利其器
一直以来MacBook是大多数开发者的首选,无论是macOS的便利性,还是MBP的外观,更或者是为了装13,我一直认为一个开发者必须得拥有一部MBP.虽然最后的因素是大多数的. 终于在我的努力下说服下 ...
- 旅游公司租车问题 —— 动态规划 v.s. + Leapms线性规划
有一个旅游公司承包一条旅游线路,未来四周内的大巴车需求分别是:4辆.1辆.4辆和5辆.该公司向租车公司租赁服务,租车公司的计价方案是:租车收取一次性手续费3000,每车每周费用2000.求最节省租车方 ...
- JAVA WEB快速入门之环境搭建
前言 我是一直致力于:.NET技术栈.WEB前端.架构设计相关的开发与管理工作,但因国内大环境影响及公司技术方向发生转变(由.NET全部转为JAVA),需要熟练掌握JAVA WEB相关的知识,故我也得 ...