这篇文章主要介绍“如何在Centos7.4下部署mysql5.7.24”,在日常操作中,相信很多人在如何在Centos7.4下部署mysql5.7.24问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”如何在Centos7.4下部署mysql5.7.24”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!在安装mysql前需要对服务器的环境做一些配置:1、主机名解析,/etc/hosts配置;2、JDK环境变量配置;3、Mysql5.7.24的安装;一、环境操作系统:Centos7.4Mysql数据库:mysql-5.7.24-el7-x86_64.tarJDK:jdk-8u131-linux-x64.tar.gz首先需要将Mysql软件和JDK都上传到服务器上。1、配置主机名解析vi /etc/hosts主机名IP地址例如:主机名IP地址test192.168.1.102、JDK环境配置通常我将软件解压后放在/usr/java目录下,java文件夹需要自己创建:mkdir /usr/java然后解压 jdk-8u131-linux-x64.tar.gz 到 /usr/java目录tar -xzf jdk-8u131-linux-x64.tar.gz -C /usr/java设置环境变量/etc/profile文件里:vi /etc/profile按 i 键进入编辑模式。在 /etc/profile 文件中添加以下信息:export JAVA_HOME=/usr/java/jdk1.8.0_131export JRE_HOME=${JAVA_HOME}/jreexport CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATHexport JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/binexport PATH=$PATH:${JAVA_PATH}按 Esc 键退出编辑模式,输入 :wq 保存并关闭文件。加载环境变量使之生效:source /etc/profile查看 jdk 版本。当出现 jdk 版本信息时,表示 JDK 已经安装成功。#java -versionjava version “1.8.0_141″Java(TM) SE Runtime Environment (build 1.8.0_141-b15)Java HotSpot(TM) 64-Bit Server VM (build 25.141-b15, mixed mode)二、安装mysql
1、在安装mysql前,创建mysql用户groupadd mysqluseradd -g mysql mysql2、然后解压缩mysql-5.7.24-el7-x86_64.tar,会生成mysql-5.7.24-el7-x86_64文件夹,使用mv命令将其名字改为mysql,并放到/usr/local/目录下。mv mysql-5.7.24-el7-x86_64 /usr/local/mysql3、建立data目录,进入到/usr/local/mysql/目录,创建data目录mkdir data4、修改mysql属主使用ch免费主机域名own命令mysql的属主,进入/usr/local目录,执行下面命令chown -R mysql:mysql mysql5、对mysql进行初始化首先进入/usr/local/mysql/bin目录,执行下面语句
./mysqld –user=mysql –basedir=/usr/local/mysql –datadir=/usr/local/mysql/data –initialize执行完毕后如下:
[root@YQHDB2 bin]# ./mysqld –user=mysql –basedir=/usr/local/mysql –datadir=/usr/local/mysql/data –initialize2019-02-01T08:56:56.506838Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use –explicit_defaults_for_timestamp server option (see documentation for more details).2019-02-01T08:56:56.856781Z 0 [Warning] InnoDB: New log files created, LSN=457902019-02-01T08:56:56.913915Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.2019-02-01T08:56:56.973956Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 541f5848-25ff-11e9-800d-000c297c0daa.2019-02-01T08:56:56.975026Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed’ cannot be opened.2019-02-01T08:56:56.976563Z 1 [Note] A temporary password is generated for root@localhost: fhDQ&DYMn7IW最后一行的冒号之后,是自动生成的登陆密码,一定要记住,后面会登陆数据库进行修改密码;
6、从support-files目录复制mysql.server文件到/etc/init.d/目录,并改名为mysqld,尝试启动mysqld服务进入/usr/local/mysql/support-files目录,cpmysql.server/etc/init.d/mysqld,然后使用下面命令启动mysqld服务:service mysqld start7、修改数据库密码
登陆数据库修改密码:./mysql -u root -p输入上面初始化时给的密码,使用set password=password(‘你的密码’)进行修改,修改完后,可使用新密码进行登陆。部署过程中遇到的问题处理:1、如果想再次初始化,需要将data文件夹里的内容使用rm -rf * 命令全部删除,然后再初始化;2、mysqld文件里包含了软件安装目录和数据目录,这里软件目录为basedir=/usr/local/mysql ,数据目录为datadir=/usr/local/mysql/data,可以根据自己的喜好进行调整;3、所有的错误信息保存在data目录下,以err为后缀的文件里;4、[ERROR] Could not create unix socket lock file /var/lib/mysql/mysql.sock.lock.
[ERROR] Unable to setup unix socket lock file.需要将/var/lib/目录下的mysql的属主改为mysql,如果没有mysql目录需要创建5、关于my.cnf文件在5.7里没有,这里给大家提供一个比较原始的,为5.5环境下的,具体内容如下:vi /etc/my.cnf[root@YQHDB2 support-files]# vi /etc/my.cnf# Example MySQL config file for medium systems.## This is for a system with little memory (32M – 64M) where MySQL plays# an important part, or systems up to 128M where MySQL is used together with# other programs (such as a web server)## MySQL programs look for option files in a set of# locations which depend on the deployment platform.# You can copy this option file to one of those# locations. For information about these locations, see:# http://dev.mysql.com/doc/mysql/en/option-files.html## In this file, you can use all long options that a program supports.# If you want to know which options a program supports, run the program# with the “–help” option.# The following options will be passed to all MySQL clients[client]#password = your_passwordport = 3306socket = /var/lib/mysql/mysql.sock# Here follows entries for some specific programs# The MySQL server[mysqld]port = 3306socket = /var/lib/mysql/mysql.sockskip-external-lockingkey_buffer_size = 16Mmax_allowed_packet = 1Mtable_open_cache = 64sort_buffer_size = 512Knet_buffer_length = 8Kread_buffer_size = 256Kread_rnd_buffer_size = 512Kmyisam_sort_buffer_size = 8M# Don’t listen on a TCP/IP port at all. This can be a security enhancement,# if all processes that need to connect to mysqld run on the same host.# All interaction w免费主机域名ith mysqld must be made via Unix sockets or named pipes.# Note that using this option without enabling named pipes on Windows# (via the “enable-named-pipe” option) will render mysqld useless!##skip-networking# Replication Master Server (default)# binary logging is required for replicationlog-bin=mysql-bin# binary logging format – mixed recommendedbinlog_format=mixed# required unique id between 1 and 2^32 – 1# defaults to 1 if master-host is not set# but will not function as a master if omittedserver-id = 1# Replication Slave (comment out master section to use this)## To configure this host as a replication slave, you can choose between# two methods :## 1) Use the CHANGE MASTER TO command (fully described in our manual) -# the syntax is:## CHANGE MASTER TO MASTER_HOST=
这篇文章主要讲解了“mysql数据库优化方式汇总”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“mysql数据库优化方式汇总”吧!数据库优化sql语句优化索引优化加缓存读写分离分区分布式数据库(垂直切分)水平切分…