Centos 8二进制安装Mysql-8.0.23
Posted y_zilong
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Centos 8二进制安装Mysql-8.0.23相关的知识,希望对你有一定的参考价值。
1.mysql tar包的下载
#下载官网:https://downloads.mysql.com/archives/community/
2、解压
[root@cent8_yzil ~]# tar xf mysql-8.0.23-linux-glibc2.12-x86_64.tar.xz
[root@cent8_yzil ~]# mkdir /app
[root@cent8_yzil ~]# mv mysql-8.0.23-linux-glibc2.12-x86_64 /app/mysql
[root@cent8_yzil ~]# cd /app/
[root@cent8_yzil app]# ls
mysql
[root@cent8_yzil app]#
3、配置环境变量
[root@cent8_yzil ~]# vi /etc/profile.d/mysql.sh
export PATH=/app/mysql/bin:$PATH
[root@cent8_yzil ~]# source /etc/profile.d/mysql.sh
注意:必须以.sh结尾
4、配置数据目录及权限
#创建数据目录
[root@cent8_yzil ~]# mkdir -p /data/mysql
#创建mysql启动用户
[root@cent8_yzil ~]# useradd -s /sbin/nologin mysql
#更改目录用户
[root@cent8_yzil ~]# chown mysql.mysql /data/mysql
[root@cent8_yzil ~]# chown -R mysql.mysql /app/mysql
5、初始化
#初始化数据,及管理员的临时密码
#如果有配置文件,根据配置文件,将相关文件初始化到对应位置
#如果没有配置文件,可在命令后面跟上相关选项:--basedir,--datadir,--pid-file,--log-error等,否则按编译时的默认规则来
#默认basedir=/usr/local/mysql,datadir=/usr/local/mysql/data/
#-initialize-insecure,不生成密码
#如果是centos7这里我们将mariadb库自带的/etc/my.cnf删除在初始化
注意:
mysql5.7开始,增加了新的安全机制,不允许无密码登陆。
#初始化完成后,会生成一个临时密码,记录下来
#初始化过程,数据目录不能有数据,如果有,清空
[root@cent8_yzil ~]# mysqld --initialize --user=mysql --basedir=/app/mysql --datadir=/data/mysql
2021-05-10T11:46:48.897155Z 0 [System] [MY-013169] [Server] /app/mysql/bin/mysqld (mysqld 8.0.23) initializing of server in progress as process 49478
2021-05-10T11:46:48.921435Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-05-10T11:46:49.740473Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-05-10T11:46:51.567124Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: =Mj.a-E9U5Vo
[root@cent8_yzil ~]#
#注意::后面密码要记下来
6、重新初始化
注意:重新初始化,数据目录必须为空
[root@cent8_yzil ~]# rm -rf /data/mysql/*
[root@cent8_yzil ~]# mysqld --initialize --user=mysql --basedir=/app/mysql --datadir=/data/mysql
2021-05-10T11:59:23.009242Z 0 [System] [MY-013169] [Server] /app/mysql/bin/mysqld (mysqld 8.0.23) initializing of server in progress as process 49778
2021-05-10T11:59:23.021150Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-05-10T11:59:23.522328Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-05-10T11:59:24.536485Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: XfPbbIwBw3>A
[root@cent8_yzil ~]#
7、定义配置文件
[root@cent8_yzil ~]# vi /etc/my.cnf
#服务端配置
[mysqld]
user=mysql
basedir=/app/mysql
datadir=/data/mysql
server_id=1
port=3306
socket=/tmp/mysql.sock
log-error=/var/log/mysql/mysql.log
character-set-server=utf8mb4
#客户端配置
[mysql]
socket=/tmp/mysql.sock
prompt="\\\\r:\\\\m:\\\\s(\\\\u@\\\\h) [\\\\d]>\\\\_" #自定义提示符
default-character-set=utf8mb4
[root@cent8_yzil ~]#
#创建日志目录,并修改权限
[root@cent8_yzil ~]# mkdir /var/log/mysql
[root@cent8_yzil ~]# chown mysql.mysql /var/log/mysql
8、启动
#mysql自带一个启动脚本
/app/mysql/support-files/mysql.server
[root@cent8_yzil ~]# ls /app/mysql/support-files/mysql.server
/app/mysql/support-files/mysql.server
[root@cent8_yzil ~]# cd /app/mysql/support-files/
[root@cent8_yzil support-files]# ./mysql.server start
Starting MySQL.Logging to '/var/log/mysql/mysql.log'.
. SUCCESS!
[root@cent8_yzil support-files]#
#查看mysqld的进程
[root@cent8_yzil ~]# ps -elf |grep mysqld
4 S root 49979 1 0 80 0 - 3241 - 08:07 pts/1 00:00:00 /bin/sh /app/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/cent8_yzil.example.com.pid
4 S mysql 50164 49979 0 80 0 - 563411 x64_sy 08:07 pts/1 00:00:01 /app/mysql/bin/mysqld --basedir=/app/mysql --datadir=/data/mysql --plugin-dir=/app/mysql/lib/plugin --user=mysql --log-error=/var/log/mysql/mysql.log --pid-file=/data/mysql/cent8_yzil.example.com.pid --socket=/tmp/mysql.sock --port=3306
0 S root 50266 43508 0 80 0 - 3028 - 08:10 pts/1 00:00:00 grep --color=auto mysqld
[root@cent8_yzil ~]#
9、登录
#使用初始化时候的密码进行登录
#默认密码登陆,不允许作任何操作,需要先改密码
[root@cent8_yzil ~]# mysql -uroot -p'XfPbbIwBw3>A'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \\g.
Your MySQL connection id is 8
Server version: 8.0.23
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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.
hello [(none)]>alter user root@'localhost' identified by 'redhat';
Query OK, 0 rows affected (0.01 sec)
hello [(none)]>exit
[root@cent8_yzil ~]#
#查看以下账号密码信息
hello [(none)]>select user,host,authentication_string from mysql.user;
+------------------+-----------+------------------------------------------------------------------------+
| user | host | authentication_string |
+------------------+-----------+------------------------------------------------------------------------+
| mysql.infoschema | localhost | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| mysql.session | localhost | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| mysql.sys | localhost | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| root | localhost | $A$005$_7bG1]/g>jp`KNQ;nDPAYE0cetaZOgH/KtZUHsroWH15J8j9CUEKiypaTM2 |
+------------------+-----------+------------------------------------------------------------------------+
4 rows in set (0.00 sec)
hello [(none)]>
10、开机启动
#杀死所有mysqld进程
[root@cent8_yzil ~]# killall mysqld
#编写systemd配置文件
[root@cent8_yzil ~]# vi /etc/systemd/system/mysqld.service
[root@cent8_yzil ~]# cat /etc/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/app/mysql/bin/mysqld --defaults-file=/etc/my.cnf
[root@cent8_yzil ~]#
[root@cent8_yzil ~]# systemctl daemon-reload
[root@cent8_yzil ~]# systemctl enable mysqld
[root@cent8_yzil ~]# systemctl start mysqld
[root@cent8_yzil ~]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/etc/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2021-05-11 21:02:31 EDT; 4min 19s ago
Main PID: 3387 (mysqld)
Tasks: 38 (limit: 11251)
Memory: 348.3M
CGroup: /system.slice/mysqld.service
└─3387 /app/mysql/bin/mysqld --defaults-file=/etc/my.cnf
May 11 21:02:31 cent8_yzil.example.com systemd[1]: Started MySQL Server.
[root@cent8_yzil ~]#
以上是关于Centos 8二进制安装Mysql-8.0.23的主要内容,如果未能解决你的问题,请参考以下文章