MySQL 8.1.0二进制包安装配置详解


官方多平台下载地址
https://dev.mysql.com/downloads/mysql/
Linux Generic(通用版)最新版64位下载地址     [8.1.0]
https://dev.mysql.com/get/Downloads/MySQL-8.1/mysql-8.1.0-linux-glibc2.17-x86_64.tar.xz

安装实践
环境
CentOS Linux release 7.6.1810 (Core) 
[root@node250 ~]# uname -r
3.10.0-957.el7.x86_64
下载
[root@node250 ~]#  wget https://dev.mysql.com/get/Downloads/MySQL-8.1/mysql-8.1.0-linux-glibc2.17-x86_64.tar.xz

移除旧的mariadb客户端:
[root@node250 mysql]# rpm -e mariadb-libs-5.5.60-1.el7_5.x86_64 --nodeps

创建mysql用户名与用户组
[root@sea_bj_master src]# useradd -r -s /sbin/nologin -c 'mysql application run user'  mysql

解压MySQL压缩包,并将解压包移动至/usr/local目录下
[root@sea_bj_master src]#tar -xvJf  mysql-8.1.0-linux-glibc2.17-x86_64.tar.xz
[root@node250 ~]# ll
总用量 437876
-rw-------. 1 root root      1571 4月  23 2020 anaconda-ks.cfg
drwxr-xr-x. 9 root root       129 7月  26 10:56 mysql-8.1.0-linux-glibc2.17-x86_64
-rw-r--r--. 1 root root 448377800 7月  26 10:34 mysql-8.1.0-linux-glibc2.17-x86_64.tar.xz
[root@node250 ~]# mv mysql-8.1.0-linux-glibc2.17-x86_64 /usr/local/mysql-8.1.0/

创建软连接, 方便今后升级本体程序不影响配置文件
[root@node250 local]# ln -s /usr/local/mysql-8.1.0-linux-glibc2.17-x86_64  /usr/local/mysql -v
"/usr/local/mysql" -> "/usr/local/mysql-8.1.0-linux-glibc2.17-x86_64"

创建MySQL数据导入/导出数据专放目录文件夹, 修改权限
[root@node250 mysql]#  mkdir -v /usr/local/mysql/mysql-files
mkdir: 已创建目录 "/usr/local/mysql/mysql-files"

创建数据文件夹
[root@node250 mysql]# mkdir /usr/local/mysql/data -v
mkdir: 已创建目录 "/usr/local/mysql/data"

修改MySQL目录所有者和所有组
修改 MySQL 数据目录与 数据导入/导出专放目录的所属用户与所属组 
[root@node250 mysql]# chown mysql.mysql /usr/local/mysql-8.1.0-linux-glibc2.17-x86_64/ -R
 
重命名不使用系统自带 MySQL 配置文件 /etc/my.cnf [ debian类系统在 /etc/mysql/my.cnf ]
[root@node250 mysql]#  mv /etc/my.cnf{,.old} -v
"/etc/my.cnf" -> "/etc/my.cnf.old"

创建MySQL配置文件my.cnf, 指定数据目录
[root@node250 mysql]# cat /usr/local/mysql/my.cnf
[mysqld]
user=mysql
bind_address=0.0.0.0
character_set_server=utf8mb4
skip_name_resolve = 1
max_connections = 800
max_connect_errors = 1000
lower_case_table_names=1
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock

[mysqld_safe]
log-error=/usr/local/mysql/log-error.log
pid-file=/usr/local/mysql/mysql.pid

创建软连接:
[root@node250 mysql]# ln -sf /usr/local/mysql/my.cnf /etc/my.cnf

初始化:指定my.cnf文件位置:
[root@node250 mysql]# /usr/local/mysql/bin/mysqld --defaults-file=/usr/local/mysql/my.cnf --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql  --lower-case-table-names=1 --initialize
2023-07-26T03:25:28.254819Z 0 [System] [MY-015017] [Server] MySQL Server Initialization - start.
2023-07-26T03:25:28.258266Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2023-07-26T03:25:28.258622Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.1.0) initializing of server in progress as process 6266
2023-07-26T03:25:28.287308Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-07-26T03:25:29.891997Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-07-26T03:25:35.513718Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Fs;kCoh,s1ei
2023-07-26T03:25:40.665052Z 0 [System] [MY-015018] [Server] MySQL Server Initialization - end.


注意:下面是系统初始化时的临时密码:
root@localhost: Fs;kCoh,s1ei

配置环境变量:
vim /etc/profile
在文件末尾添加以下行:
export PATH=$PATH:/usr/local/mysql/bin
执行以下命令使环境变量生效:
source /etc/profile

通过脚本启动:
/usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/my.cnf

创建启动脚本[systemd]
[root@node250 mysql]#  cat /usr/lib/systemd/system/mysqld.service
#
# Simple MySQL systemd service file
#
# systemd supports lots of fancy features, look here (and linked docs) for a full list: 
#   http://www.freedesktop.org/software/systemd/man/systemd.exec.html
#
# Note: this file ( /usr/lib/systemd/system/mysql.service )
# will be overwritten on package upgrade, please copy the file to 
#
#  /etc/systemd/system/mysql.service 
#  
# to make needed changes.

# systemd-delta can be used to check differences between the two mysql.service files.
#
[Unit]
Description=MySQL Community Server
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
Alias=mysqld.service
[Service]
User=mysql
Group=mysql
# Execute pre and post scripts as root
PermissionsStartOnly=true
# Needed to create system tables etc.
#ExecStartPre=/usr/bin/mysql-systemd-start pre
# Start main service
ExecStart=/usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/my.cnf
# Don't signal startup success before a ping works
#ExecStartPost=/usr/bin/mysql-systemd-start post
# Give up if ping don't get an answer
TimeoutSec=600
Restart=always
PrivateTmp=false


systemd加载启动配置文件
[root@node250 mysql]# systemctl daemon-reload

启动MySQL服务
[root@node250 mysql]# systemctl start mysqld
[root@node250 mysql]# systemctl status mysqld
● mysqld.service - MySQL Community Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
   Active: active (running) since 三 2023-07-26 11:35:03 CST; 13min ago
Main PID: 6363 (mysqld_safe)
   CGroup: /system.slice/mysqld.service
           ├─6363 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/my.cnf
           └─6574 /usr/local/mysql/bin/mysqld --defaults-file=/usr/local/mysql/my.cnf --basedir=/usr/local/mys...


7月 26 11:35:03 node250 systemd[1]: Started MySQL Community Server.
7月 26 11:35:03 node250 mysqld_safe[6363]: 2023-07-26T03:35:03.825773Z mysqld_safe Logging to '/usr/local...og'.
7月 26 11:35:03 node250 mysqld_safe[6363]: 2023-07-26T03:35:03.911201Z mysqld_safe Starting mysqld daemon...data
Hint: Some lines were ellipsized, use -l to show in full.


连接MySQL服务并修改初始密码
[root@node250 mysql]# mysql -uroot -p'Fs;kCoh,s1ei'
 mysql> alter user root@localhost identified by 'Rscpass123.';


查看版本信息:
mysql>
mysql> \s
--------------
mysql  Ver 8.1.0 for Linux on x86_64 (MySQL Community Server - GPL)

Connection id:                9
Current database:       
Current user:                root@localhost
SSL:                        Not in use
Current pager:                stdout
Using outfile:                ''
Using delimiter:        ;
Server version:                8.1.0
Protocol version:        10
Connection:                Localhost via UNIX socket
Server characterset:        utf8mb4
Db     characterset:        utf8mb4
Client characterset:        utf8mb4
Conn.  characterset:        utf8mb4
UNIX socket:                /tmp/mysql.sock
Binary data as:                Hexadecimal
Uptime:                        1 min 42 sec


Threads: 2  Questions: 9  Slow queries: 0  Opens: 527  Flush tables: 3  Open tables: 36  Queries per second avg: 0.088
--------------

分割线
感谢打赏
江西数库信息技术有限公司
YWSOS.COM 平台代运维解决方案
 评论
 发表评论
姓   名:

Powered by AKCMS