久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

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

212次閱讀
沒有評論

共計 7264 個字符,預計需要花費 19 分鐘才能閱讀完成。

這篇文章主要介紹“如何在 Centos7.4 下部署 mysql5.7.24”,在日常操作中,相信很多人在如何在 Centos7.4 下部署 mysql5.7.24 問題上存在疑惑,丸趣 TV 小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”如何在 Centos7.4 下部署 mysql5.7.24”的疑惑有所幫助!接下來,請跟著丸趣 TV 小編一起來學習吧!

在安裝 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= 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

———————————————————————————–

只需將上面的內容復制到 my.cnf 文件即可,具體需要什么參數,可通過網上查找;

到此,關于“如何在 Centos7.4 下部署 mysql5.7.24”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注丸趣 TV 網站,丸趣 TV 小編會繼續努力為大家帶來更多實用的文章!

正文完
 
丸趣
版權聲明:本站原創文章,由 丸趣 2023-07-28發表,共計7264字。
轉載說明:除特殊說明外本站除技術相關以外文章皆由網絡搜集發布,轉載請注明出處。
評論(沒有評論)
主站蜘蛛池模板: 建德市| 克什克腾旗| 麦盖提县| 佛学| 泗洪县| 安康市| 桓台县| 武平县| 彭泽县| 乡城县| 湟源县| 万盛区| 新营市| 仙游县| 天柱县| 孟村| 沾益县| 泰兴市| 泰顺县| 高淳县| 始兴县| 花莲县| 慈溪市| 宣化县| 鸡西市| 双流县| 孝感市| 新竹市| 潢川县| 南丰县| 玉门市| 丹巴县| 临清市| 安西县| 台北县| 岳阳县| 桑日县| 锦州市| 永胜县| 赤壁市| 时尚|