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 ...
随机推荐
- hadoop 笔记(hive)
//**********************************//安装配置1. 修改配置文件 1.1 在conf文件夹下 touch hive-site.xml <configurat ...
- 从壹开始前后端分离 [ Vue2.0+.NET Core2.1] 二十四║ Vuex + JWT 实现授权验证登录
壹周回顾 哈喽,又是元气满满的一个周一,又与大家见面了,周末就是团圆节了,正好咱们的前后端也要团圆了,为什么这么说呢,因为以后的开发可能就需要前后端一起了,两边也终于会师了,还有几天Vue系列就基本告 ...
- ASP.NET Core MVC应用程序中的后台工作任务
在应用程序的内存中缓存常见数据(如查找)可以显着提高您的MVC Web应用程序性能和响应时间.当然,这些数据必须定期刷新. 当然你可以使用任何方法来更新数据,例如Redis中就提供了设定缓存对象的生命 ...
- 原子操作&普通锁&读写锁
一:原子操作CAS(compare-and-swap) 原子操作分三步:读取addr的值,和old进行比较,如果相等,则将new赋值给*addr,他能保证这三步一起执行完成,叫原子操作也就是说它不能再 ...
- 第一册:Lesson 123.
原文:A trip to Australia. question:Who is the man with the beard? Look ,Scott.This is a photograph I t ...
- SpringBoot2.0整合Redis
Spring Boot2.0在2018年3月份正式发布,相比1.0还是有比较多的改动,例如SpringBoot 自2.0起支持jdk1.8及以上的版本.第三方类库升级.响应式 Spring 编程支持等 ...
- ConcurrentHashMap1.8源码分析
文章简介 想必大家对HashMap数据结构并不陌生,JDK1.7采用的是数组+链表的方式,JDK1.8采用的是数组+链表+红黑树的方式.虽然JDK1.8对于HashMap有了很大的改进,提高了存取效率 ...
- Eclipse4JavaEE配置Tomcat运行环境
如果我们想搭一个网站,我们可以使用Eclipse for JavaEE IDE进行开发. 初次使用需要配置网站的运行环境,可以去Apache官网下载Tomcat 8.5或Tomcat 9的版本 然后打 ...
- WEB前端需要了解的XML相关基础知识
什么是 XML? XML 指可扩展标记语言(EXtensible Markup Language) XML 是一种标记语言,很类似 HTML XML 的设计宗旨是传输数据,而非显示数据 XML 标签没 ...
- wordpress主题
1.创建wordpress主题:在themes文件下建立新主题black文件夹 2.在black文件夹中放入index.php和style.css文件,其中index对style.css文件的引用 & ...