如何在Centos7.4下部署mysql5.7.24

這篇文章主要介紹“如何在Centos7.4下部署MySQL5.7.24”,在日常操作中,相信很多人在如何在Centos7.4下部署mysql5.7.24問題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”如何在Centos7.4下部署mysql5.7.24”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!

創(chuàng)新互聯(lián)長(zhǎng)期為上1000+客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺(tái),與合作伙伴共同營(yíng)造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為軹城企業(yè)提供專業(yè)的成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)軹城網(wǎng)站改版等技術(shù)服務(wù)。擁有10余年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開發(fā)。

在安裝mysql前需要對(duì)服務(wù)器的環(huán)境做一些配置:

1、主機(jī)名解析,/etc/hosts配置;

2、JDK環(huán)境變量配置;

3、Mysql5.7.24的安裝;

一、環(huán)境

操作系統(tǒng):Centos7.4

Mysql數(shù)據(jù)庫(kù):mysql-5.7.24-el7-x86_64.tar

JDK:jdk-8u131-linux-x64.tar.gz

首先需要將Mysql軟件和JDK都上傳到服務(wù)器上。

1、配置主機(jī)名解析

vi /etc/hosts

主機(jī)名    IP地址

例如:

主機(jī)名    IP地址

test        192.168.1.10

2、JDK環(huán)境配置

通常我將軟件解壓后放在/usr/java目錄下,java文件夾需要自己創(chuàng)建:

mkdir /usr/java

然后解壓 jdk-8u131-linux-x64.tar.gz 到 /usr/java目錄

tar -xzf jdk-8u131-linux-x64.tar.gz -C /usr/java

設(shè)置環(huán)境變量/etc/profile文件里:

vi /etc/profile

按 i 鍵進(jìn)入編輯模式。

在 /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 保存并關(guān)閉文件。

加載環(huán)境變量使之生效:source /etc/profile

查看 jdk 版本。當(dāng)出現(xiàn) jdk 版本信息時(shí),表示 JDK 已經(jīng)安裝成功。

#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前,創(chuàng)建mysql用戶

groupadd mysql

useradd -g mysql mysql

2、然后解壓縮mysql-5.7.24-el7-x86_64.tar,會(huì)生成mysql-5.7.24-el7-x86_64文件夾,使用mv命令將其名字改為mysql,并放到/usr/local/目錄下。

mv mysql-5.7.24-el7-x86_64 /usr/local/mysql

3、建立data目錄,進(jìn)入到/usr/local/mysql/目錄,創(chuàng)建data目錄

mkdir  data

4、修改mysql屬主

使用chown命令mysql的屬主,進(jìn)入/usr/local目錄,執(zhí)行下面命令

chown -R mysql:mysql mysql

5、對(duì)mysql進(jìn)行初始化

首先進(jìn)入/usr/local/mysql/bin目錄,執(zhí)行下面語(yǔ)句

./mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize

執(zhí)行完畢后如下:

[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

最后一行的冒號(hào)之后,是自動(dòng)生成的登陸密碼,一定要記住,后面會(huì)登陸數(shù)據(jù)庫(kù)進(jìn)行修改密碼;
6、從support-files目錄復(fù)制mysql.server文件到/etc/init.d/目錄,并改名為mysqld,嘗試啟動(dòng)mysqld服務(wù)

進(jìn)入/usr/local/mysql/support-files目錄,cp mysql.server /etc/init.d/mysqld,然后使用下面命令啟動(dòng)mysqld服務(wù):

service mysqld start

7、修改數(shù)據(jù)庫(kù)密碼

登陸數(shù)據(jù)庫(kù)修改密碼:

./mysql -u root -p

輸入上面初始化時(shí)給的密碼,使用set password=password('你的密碼')進(jìn)行修改,修改完后,可使用新密碼進(jìn)行登陸。

部署過程中遇到的問題處理:

1、如果想再次初始化,需要將data文件夾里的內(nèi)容使用rm -rf * 命令全部刪除,然后再初始化;

2、mysqld文件里包含了軟件安裝目錄和數(shù)據(jù)目錄,這里軟件目錄為basedir=/usr/local/mysql ,數(shù)據(jù)目錄為datadir=/usr/local/mysql/data,可以根據(jù)自己的喜好進(jìn)行調(diào)整;

3、所有的錯(cuò)誤信息保存在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目錄需要?jiǎng)?chuàng)建

5、關(guān)于my.cnf文件在5.7里沒有,這里給大家提供一個(gè)比較原始的,為5.5環(huán)境下的,具體內(nèi)容如下:

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=<host>, MASTER_PORT=<port>,

#    MASTER_USER=<user>, MASTER_PASSWORD=<password> ;

#

#    where you replace <host>, <user>, <password> by quoted strings and

#    <port> by the master's port number (3306 by default).

#

#    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     =   <hostname>

#

# The username the slave will use for authentication when connecting

# to the master - required

#master-user     =   <username>

#

# The password the slave will authenticate with when connecting to

# the master - required

#master-password =   <password>

#

# The port the master is listening on.

# optional - defaults to 3306

#master-port     =  <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

-----------------------------------------------------------------------------------

只需將上面的內(nèi)容復(fù)制到my.cnf文件即可,具體需要什么參數(shù),可通過網(wǎng)上查找;

到此,關(guān)于“如何在Centos7.4下部署mysql5.7.24”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!

本文題目:如何在Centos7.4下部署mysql5.7.24
標(biāo)題來(lái)源:http://www.muchs.cn/article12/ihpigc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站網(wǎng)站維護(hù)、建站公司、App設(shè)計(jì)網(wǎng)站改版、Google

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

網(wǎng)站建設(shè)網(wǎng)站維護(hù)公司