欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

CentOS 7 MySql 解压版安装配置

程序员文章站 2023-11-11 18:19:52
下载 将文件下载到CentOS服务器上,或者通过Windows下载后上传到CentOS服务器上。 (这里将文件放到/opt/soft/mysql-5.7.25-el7-x86_64.tar.gz) 安装配置 1、添加组和用户 [root@localhost ~]: groupadd mysql [r ......

下载

  1. 访问
  2. 点击downloads-->community-->mysql community server
  3. 选择要下载的版本,目前可选择的有:5.55.65.78.0,这里以5.7为例,所以选择的是5.7
  4. 操作系统选择red hat enterprise linux / oracle linux,操作系统版本选择red hat enterprise linux 7 / oracle linux 7 (x86, 64-bit),下面列表过滤的找到compressed tar archivetar压缩文件下载即可,这里选择的是mysql-5.7.25-el7-x86_64.tar.gz

将文件下载到centos服务器上,或者通过windows下载后上传到centos服务器上。

(这里将文件放到/opt/soft/mysql-5.7.25-el7-x86_64.tar.gz

安装配置

1、添加组和用户

[root@localhost ~]: groupadd mysql
[root@localhost ~]: useradd -r -g mysql mysql

2、解压到指定位置

这里准备将mysql放到/opt/program/mysql目录中。

  1. 创建/opt/program/目录。
  2. 进入到/opt/program/目录。
  3. 解压/opt/soft/mysql-5.7.25-el7-x86_64.tar.gz文件,不指定目录的话,会解压到用户所在的目录(也就是/opt/program/)。
  4. 重新命名文件夹名为mysql
  5. 创建数据库目录data
    [root@localhost ~]: mkdir /opt/program
    [root@localhost ~]: cd /opt/program
    [root@localhost program]: tar -zxvf /opt/soft/mysql-5.7.25-el7-x86_64.tar.gz
    mysql-5.7.25-el7-x86_64/bin/myisam_ftdump
    mysql-5.7.25-el7-x86_64/bin/myisamchk
    mysql-5.7.25-el7-x86_64/bin/myisamlog
    mysql-5.7.25-el7-x86_64/bin/myisampack
    mysql-5.7.25-el7-x86_64/bin/mysql
    …………
    [root@localhost program]: mv mysql-5.7.25-el7-x86_64 mysql
    [root@localhost program]: mkdir mysql/data

3、给用户和组赋权

[root@localhost ~]: chown -r mysql:mysql /opt/program/mysql

4、初始化mysql数据库

初始化需要指定mysql程序的目录以及数据库的目录

[root@localhost ~]: /opt/program/mysql/bin/mysqld --initialize --user=mysql --basedir=/opt/program/mysql --datadir=/opt/program/mysql/data
2019-03-16t14:28:52.317678z 0 [warning] timestamp with implicit default value is deprecated. please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-03-16t14:28:54.382317z 0 [warning] innodb: new log files created, lsn=45790
2019-03-16t14:28:54.699000z 0 [warning] innodb: creating foreign key constraint system tables.
2019-03-16t14:28:54.772198z 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: d3d169f0-47f7-11e9-9ce7-000c291627c9.
2019-03-16t14:28:54.773910z 0 [warning] gtid table is not ready to be used. table 'mysql.gtid_executed' cannot be opened.
2019-03-16t14:28:54.775717z 1 [note] a temporary password is generated for root@localhost: hxwvzi*0-e3<

警告可以先不管,最后的位置是随机生成的root密码hxwvzi*0-e3<

5、配置my.cnf文件

mysql启动时,默认会查找/etc/my.cnf文件作为配置文件。

[root@localhost ~]: vi /etc/my.cnf

配置示例如下:

[mysql]
default-character-set=utf8
 
[mysqld]
lower_case_table_names=1
basedir=/opt/program/mysql
datadir=/opt/program/mysql/data
port=3306
character-set-server=utf8
max_connections=2000
innodb_buffer_pool_size=128m
log-error=/opt/program/mysql/data/error.log
pid-file=/opt/program/mysql/data/mysql.pid
socket=/opt/program/mysql/mysql.sock

6、为mysql配置环境变量

可以通过/etc/profile文件配置。

[root@localhost ~]: vi /etc/profile

打开该文件,在最末尾的位置加上

path=$path:/opt/program/mysql/bin

保存退出,再执行

[root@localhost ~]: source /etc/profile

通过# echo $path可以查看环境变量信息

7、制作自启动服务

第一种,将mysql.server复制到/etc/ini.d/目录下配置自启动服务

[root@localhost ~]: cp /opt/program/mysql/support-files/mysql.server /etc/ini.d/mysql
[root@localhost ~]: chmod +x /etc/ini.d/mysql
[root@localhost ~]: chkconfig --add mysql

通过# chkconfig --list查看是否添加成功

然后通过service命令控制

[root@localhost ~]: service mysql start

第二种,通过systemd制作自启动服务

[root@localhost ~]: touch /etc/systemd/system/mysql.service
[root@localhost ~]: vi /etc/systemd/system/mysql.service

配置示例如下:

[unit]
description=mysql service
 
[service]
type=forking
execstart=/opt/program/mysql/support-files/mysql.server start
execstop=/opt/program/mysql/support-files/mysql.server stop
user=mysql
 
[install]
wantedby=multi-user.target

然后通过systemctl命令控制即可,启动服务和启用自启动

[root@localhost ~]: systemctl start mysql.service
[root@localhost ~]: systemctl enable mysql.service

第三种,通过systemd制作自启动服务,并且通过mysql/bin/mysqld来启动,my.cnf可以自定义位置。(参照于windows服务的启动配置) mysql.service配置示例如下:

[unit]
description=mysql service
 
[service]
execstart=/opt/program/mysql/bin/mysqld --defaults-file=/opt/program/mysql/my.cnf --user=mysql
user=mysql
 
[install]
wantedby=multi-user.target

  1. 错误:error while loading shared libraries: libaio.so.1: cannot open shared object file: no such file or directory

解决方法: 检查是否有libaio库# rpm -qa|grep libaio,如果没有则安装# yum install libaio