重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
这篇文章主要介绍“如何在Centos7.4下部署MySQL5.7.24”,在日常操作中,相信很多人在如何在Centos7.4下部署mysql5.7.24问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”如何在Centos7.4下部署mysql5.7.24”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
创新互联长期为上1000+客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为轵城企业提供专业的成都网站设计、成都网站建设,轵城网站改版等技术服务。拥有10余年丰富建站经验和众多成功案例,为您定制开发。
在安装mysql前需要对服务器的环境做一些配置:
1、主机名解析,/etc/hosts配置;
2、JDK环境变量配置;
3、Mysql5.7.24的安装;
一、环境
操作系统:Centos7.4
Mysql数据库:mysql-5.7.24-el7-x86_64.tar
JDK:jdk-8u131-linux-x64.tar.gz
首先需要将Mysql软件和JDK都上传到服务器上。
1、配置主机名解析
vi /etc/hosts
主机名 IP地址
例如:
主机名 IP地址
test 192.168.1.10
2、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_131
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATH
export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin
export PATH=$PATH:${JAVA_PATH}
按 Esc 键退出编辑模式,输入 :wq 保存并关闭文件。
加载环境变量使之生效:source /etc/profile
查看 jdk 版本。当出现 jdk 版本信息时,表示 JDK 已经安装成功。
#java -version
java 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 mysql
useradd -g mysql mysql
2、然后解压缩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/mysql
3、建立data目录,进入到/usr/local/mysql/目录,创建data目录
mkdir data
4、修改mysql属主
使用chown命令mysql的属主,进入/usr/local目录,执行下面命令
chown -R mysql:mysql mysql
5、对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 --initialize
2019-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=45790
2019-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目录,cp mysql.server /etc/init.d/mysqld,然后使用下面命令启动mysqld服务:
service mysqld start
7、修改数据库密码
登陆数据库修改密码:
./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_password
port = 3306
socket = /var/lib/mysql/mysql.sock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
port = 3306
socket = /var/lib/mysql/mysql.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_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 with 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 replication
log-bin=mysql-bin
# binary logging format - mixed recommended
binlog_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 omitted
server-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=
# MASTER_USER=
#
# where you replace
#
#
# Example:
#
# CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
# MASTER_USER='joe', MASTER_PASSWORD='secret';
#
# OR
#
# 2) Set the variables below. However, in case you choose this method, then
# start replication for the first time (even unsuccessfully, for example
# if you mistyped the password in master-password and the slave fails to
# connect), the slave will create a master.info file, and any later
# change in this file to the variables' values below will be ignored and
# overridden by the content of the master.info file, unless you shutdown
# the slave server, delete master.info and restart the slaver server.
# For that reason, you may want to leave the lines below untouched
# (commented) and instead use CHANGE MASTER TO (see above)
#
# required unique id between 2 and 2^32 - 1
# (and different from the master)
# defaults to 2 if master-host is set
# but will not function as a slave if omitted
#server-id = 2
#
# The replication master for this slave - required
#master-host =
#
# The username the slave will use for authentication when connecting
# to the master - required
#master-user =
#
# The password the slave will authenticate with when connecting to
# the master - required
#master-password =
#
# The port the master is listening on.
# optional - defaults to 3306
#master-port =
#
# binary logging - not required for slaves, but recommended
#log-bin=mysql-bin
# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /var/lib/mysql
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /var/lib/mysql
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 16M
#innodb_additional_mem_pool_size = 2M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 5M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
-----------------------------------------------------------------------------------
只需将上面的内容复制到my.cnf文件即可,具体需要什么参数,可通过网上查找;
到此,关于“如何在Centos7.4下部署mysql5.7.24”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注创新互联网站,小编会继续努力为大家带来更多实用的文章!