mysql5.7.26部署-二进制

【安装方式】

【部署-二进制安装】

[root@web02 ~]# useradd mysql -s /sbin/nologin -M

[root@web02 ~]# mkdir -p /server/tools

###官网下载

https://downloads.mysql.com/archives/community/

下载5.7.26版本,那个600M的,64位

###yum源地址

http://mirrors.163.com/mysql/Downloads/

【解压】

[root@web02 /server/tools]# tar xzvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz

###改名

[root@web02 /application]# mv mysql-5.7.26-linux-glibc2.12-x86_64 /application/mysql_5.7.26

###做个软连接,和nginx一个套路

[root@web02 /application]# ln -s mysql_5.7.26/ ./mysql

[root@web02 /application]# ls

mysql  mysql_5.7.26

[root@web02 /application]# ll

total 0

lrwxrwxrwx 1 root root  13 Dec 26 20:19 mysql -> mysql_5.7.26/

drwxr-xr-x 9 root root 120 Dec 26 20:16 mysql_5.7.26

至此安装结束,不需要编译,相当于windows绿色版,解压完了直接用即可

【卸载centos7自带的mariadb库防止冲突】

[root@web02 ~]# rpm -qa mariadb-libs

mariadb-libs-5.5.44-2.el7.centos.x86_64

[root@web02 ~]# rpm -e --nodeps mariadb-libs

【修改my.cnf配置文件】

5.7.26的mysql没有默认的模板了,只能自己创建

[root@web02 ~]# vim /etc/my.cnf

[mysqld]

user = mysql

basedir = /application/mysql/

datadir = /application/mysql/data

socket = /tmp/mysql.sock

server_id = 1

port = 3306

log_error = /application/mysql/data/luoqi_mysql.err

[mysql]

socket = /tmp/mysql.sock

prompt = luoqi [\\d]>  ##提示符

【初始化数据库】

###检查mariadb是否已经卸载干净

[root@web02 ~]# rpm -qa mariadb-libs

###安装mysql依赖包

[root@web02 ~]# yum install -y libaio-devel

###创建数据目录

[root@web02 ~]# mkdir /application/mysql/data

###授权目录mysql角色

[root@web02 ~]# chown -R mysql.mysql /application/mysql

坑,光给软连接授权没用,要给原始目录做授权

[root@web02 ~]# chown -R mysql.mysql /application/mysql_5.7.26/

###初始化

[root@web02 ~]# /application/mysql/bin/mysqld --initialize-insecure --user=mysql \

--basedir=/application --datadir=/application/mysql/data

###参数解释

--initialize-insecure 关闭安全策略

--initialize 开启安全策略

--user=mysql msql用户

--basedir=/application mysql根目录

--datadir mysql数据目录

###如果不提示说明OK,提示warn可以忽略,但是有error就不行!

###检测是否初始化成功

[root@web02 /application]# ll /application/mysql/data/

total 110632

-rw-r----- 1 mysql mysql      56 Dec 26 21:06 auto.cnf

-rw-r----- 1 mysql mysql      419 Dec 26 21:06 ib_buffer_pool

-rw-r----- 1 mysql mysql 12582912 Dec 26 21:06 ibdata1

-rw-r----- 1 mysql mysql 50331648 Dec 26 21:06 ib_logfile0

-rw-r----- 1 mysql mysql 50331648 Dec 26 21:06 ib_logfile1

-rw-r----- 1 mysql mysql    1035 Dec 26 21:06 luoqi_mysql.err

drwxr-x--- 2 mysql mysql    4096 Dec 26 21:06 mysql

drwxr-x--- 2 mysql mysql    8192 Dec 26 21:06 performance_schema

drwxr-x--- 2 mysql mysql    8192 Dec 26 21:06 sys

【启动mysql】

###制作C7systemctl管理服务

vim /etc/systemd/system/mysqld.service

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

[Unit]

Description=MySql Server by luoqi

After=network.target syslog.target

[Install]

WantedBy=multi-user.target

[Service]

User=mysql

Group=mysql

ExecStart=/application/mysql/bin/mysqld --defaults-file=/etc/my.cnf

LimitNOFILE=5000

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

【启动服务】

[root@web02 /application]# systemctl start mysqld.service

[root@web02 /application]# systemctl enable mysqld.service

[root@web02 /application]# systemctl status mysqld.service

● mysqld.service - MySql Server by luoqi

  Loaded: loaded (/etc/systemd/system/mysqld.service; enabled; vendor preset: disabled)

  Active: active (running) since Sat 2020-12-26 22:50:33 CST; 6s ago

Main PID: 3912 (mysqld)

  CGroup: /system.slice/mysqld.service

          └─3912 /application/mysql/bin/mysqld --defaults-file=/etc/my.cnf

Dec 26 22:50:33 web02 systemd[1]: Started MySql Server by luoqi.

###查看端口

[root@web02 /application]# netstat -tlunp|grep 3306

tcp6      0      0 :::3306                :::*                    LISTEN      3912/mysqld

###配置环境变量

[root@web02 /application]# vim /etc/profile <<=添加如下内容

export PATH=/application/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

[root@web02 /application]# . /etc/profile

###登陆成功!

[root@web02 ~]# mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 3

Server version: 5.7.26 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

luoqi [(none)]>

【图形化操作mysql】

下载Navicat,用ssh隧道连接即可

【错误提示1】

###原因,用root用户执行的编译安装,mysql不建议用root用户启用mysql进程

[root@web01 application]# /application/mysql/bin/mysqld

2020-12-28T01:27:20.453028Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2020-12-28T01:27:20.453143Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled

2020-12-28T01:27:20.453169Z 0 [Note] /application/mysql/bin/mysqld (mysqld 5.7.30) starting as process 8869 ...

2020-12-28T01:27:20.455760Z 0 [ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!

2020-12-28T01:27:20.455782Z 0 [ERROR] Aborting

2020-12-28T01:27:20.455799Z 0 [Note] Binlog end

2020-12-28T01:27:20.455845Z 0 [Note] /application/mysql/bin/mysqld: Shutdown complete

###解决方式1

[root@web01 application]# /application/mysql/bin/mysqld --user=mysql

###解决方式2

在my.cnf的[mysqld]模块下添加user = mysql

【错误2】

如果没用systemctl管理,而是直接用mysqld启动,那么就会卡住不动,因为是一个后台进程。可以用

mysqld & 后台运行即可

【错误3】

mysql进入数据库发现没有databases,因为你指定的用户是mysql,而进入只有root用户才能看到user表

但是用systemctl管理之后默认mysql进去就是root权限


【启动方式补充】

针对于mysql5.7.26版本除了systemctl管理也可以脚本启动,这个脚本在

[root@nfs01 app]# ll /app/mysql/support-files/mysql.server

-rwxr-xr-x 1 mysql mysql 10576 Apr 13  2019 /app/mysql/support-files/mysql.server

后面跟 start|stop|restart即可启动mysql

【初始化数据库安全参数补充】

如果加了--initialize-insecure,那么部署之后直接msyql -u root可以直接登录

如果加了--initialize,仔细看输出会生成一组随机密码

[root@nfs01 app]# /app/mysql/bin/mysqld --initialize --user=mysql --basedir=/app/mysql --datadir=/data-mysql

2021-02-10T09:10:12.692639Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2021-02-10T09:10:12.827988Z 0 [Warning] InnoDB: New log files created, LSN=45790

2021-02-10T09:10:12.851360Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.

2021-02-10T09:10:12.912023Z 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: c838dabd-6b7f-11eb-9a5e-000c29f7b211.

2021-02-10T09:10:12.913725Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.

2021-02-10T09:10:12.915724Z 1 [Note] A temporary password is generated for root@localhost: 7IyoNsP(!Ue>

之后用这个默认root密码登录进mysql

你可能感兴趣的:(mysql5.7.26部署-二进制)