Centos7.4下部署mysql5.7.24

在安装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文件即可,具体需要什么参数,可通过网上查找;



来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/30100210/viewspace-2565374/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/30100210/viewspace-2565374/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
资源包主要包含以下内容: ASP项目源码:每个资源包中都包含完整的ASP项目源码,这些源码采用了经典的ASP技术开发,结构清晰、注释详细,帮助用户轻松理解整个项目的逻辑和实现方式。通过这些源码,用户可以学习到ASP的基本语法、服务器端脚本编写方法、数据库操作、用户权限管理等关键技术。 数据库设计文件:为了方便用户更好地理解系统的后台逻辑,每个项目中都附带了完整的数据库设计文件。这些文件通常包括数据库结构图、数据表设计文档,以及示例数据SQL脚本。用户可以通过这些文件快速搭建项目所需的数据库环境,并了解各个数据表之间的关系和作用。 详细的开发文档:每个资源包都附有详细的开发文档,文档内容包括项目背景介绍、功能模块说明、系统流程图、用户界面设计以及关键代码解析等。这些文档为用户提供了深入的学习材料,使得即便是从零开始的开发者也能逐步掌握项目开发的全过程。 项目演示与使用指南:为帮助用户更好地理解和使用这些ASP项目,每个资源包中都包含项目的演示文件和使用指南。演示文件通常以视频或图文形式展示项目的主要功能和操作流程,使用指南则详细说明了如何配置开发环境、部署项目以及常见问题的解决方法。 毕业设计参考:对于正在准备毕业设计的学生来说,这些资源包是绝佳的参考材料。每个项目不仅功能完善、结构清晰,还符合常见的毕业设计要求和标准。通过这些项目,学生可以学习到如何从零开始构建一个完整的Web系统,并积累丰富的项目经验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值