CentOS 7 MySql 解压版安装配置

 

下载

  1. 访问www.mysql.com
  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 --lower-case-table-names=1
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

错误1:

Starting MySQL.. ERROR! The server quit without updating PID file (/usr/local/mysql/data/mysql.pid). 

解决:1.在对应文件夹下新建一个mysq.pid

 

错误2:

Different lower_case_table_names settings for server ('1') and data dictionary ('0').

  • [ERROR] [MY-011087] [Server] Different lower_case_table_names settings for server ('1') and data dictionary ('0').
[ERROR] [MY-011087] [Server] Different lower_case_table_names settings for server ('0') and data dictionary ('1').
 
 解决:在 /etc/my.cnf 中配置为0
 
 
posted on 2021-12-06 20:42  博客园197  阅读(837)  评论(0编辑  收藏  举报