二进制源码部署mysql8.0.35

二进制部署mysql8.0.35

powershell 复制代码
创建mysql用户
[root@zyq ~]#: useradd -r -s /sbin/nologin -M mysql
[root@zyq ~]#: id mysql 
uid=990(mysql) gid=990(mysql) groups=990(mysql)

上传mysql文件
[root@zyq ~]#: ls
anaconda-ks.cfg  
mysql-8.0.35-linux-glibc2.28-x86_64.tar.xz



解压
[root@zyq ~]#: tar xf mysql-8.0.35-linux-glibc2.28-x86_64.tar.xz -C  /usr/local/
[root@zyq ~]#: cd /usr/local/
[root@zyq local]#: ls
bin  games  include  lib64    mysql-8.0.35-linux-glibc2.28-x86_64  share
etc  httpd  lib      libexec  sbin                                 src
[root@zyq local]#: mv mysql-8.0.35-linux-glibc2.28-x86_64/ mysql

设置环境变量
[root@zyq mysql]#: echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@zyq mysql]#: source /etc/profile.d/mysql.sh 
[root@zyq mysql]#: which mysql
/usr/local/mysql/bin/mysql

创建软连接
[root@zyq mysql]#: ln -s /usr/local/mysql/include /usr/include/mysql

配置lib库文件
[root@zyq mysql]#: vi /etc/ld.so.conf.d/mysql.conf
[root@zyq mysql]#: cat /etc/ld.so.conf.d/mysql.conf
/use/local/mysql/lib
[root@zyq mysql]#: ldconfig 

配置man文档
[root@zyq mysql]#: vi /etc/man_db.conf
添加此行
......
MANDATORY_MANPATH                       /usr/local/mysql/man
......

更改主/组
[root@zyq mysql]#: chown -R mysql.mysql /usr/local/mysql
[root@zyq mysql]#: ll /usr/local/mysql/
total 296
drwxr-xr-x.  2 mysql mysql   4096 Oct 12 22:11 bin
drwxr-xr-x.  2 mysql mysql     38 Oct 12 22:11 docs
drwxr-xr-x.  3 mysql mysql   4096 Oct 12 22:11 include
drwxr-xr-x.  6 mysql mysql   4096 Oct 12 22:11 lib
-rw-r--r--.  1 mysql mysql 279355 Oct 12 19:45 LICENSE
drwxr-xr-x.  4 mysql mysql     30 Oct 12 22:11 man
-rw-r--r--.  1 mysql mysql    666 Oct 12 19:45 README
drwxr-xr-x. 28 mysql mysql   4096 Oct 12 22:11 share
drwxr-xr-x.  2 mysql mysql     77 Oct 12 22:11 support-files

创建数据库数据目录
初始化
[root@zyq mysql]#: mkdir /opt/data
[root@zyq mysql]#: mysqld --initialize --user=mysql --datadir=/opt/data/
2023-12-05T09:24:56.910277Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.35) initializing of server in progress as process 31786
2023-12-05T09:24:56.915155Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-12-05T09:24:57.047553Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-12-05T09:24:58.592274Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: n1O6QThtF;m=
保存密码方便查看
[root@zyq mysql]#: echo 'n1O6QThtF;mu' > pass

配置my.cnf文件
[root@zyq mysql]#: vi /etc/my.cnf
[root@zyq mysql]#: cat /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve

配置支持文件
[root@zyq mysql]#: cd support-files/
[root@zyq support-files]#: file mysql.server 
mysql.server: POSIX shell script, ASCII text executable
[root@zyq support-files]#: mkdir /etc/init.d
[root@zyq support-files]#: cp -a mysql.server /etc/init.d/mysqld
[root@zyq support-files]#: ll /etc/init.d/mysqld 
-rwxr-xr-x. 1 mysql mysql 10576 Oct 12 21:47 /etc/init.d/mysqld
指名路径(安装路径,数据路径)
[root@zyq support-files]#: vi /etc/init.d/mysqld 
basedir=/use/local/mysql
datadir=/opt/data

启动
[root@zyq support-files]#: cd 
[root@zyq ~]#: systemctl daemon-reload 
[root@zyq ~]#: service mysqld start 
Starting MySQL.Logging to '/opt/data/zyq.err'.
 SUCCESS! 
[root@zyq ~]#: ss -antl
State   Recv-Q  Send-Q   Local Address:Port    Peer Address:Port  Process  
LISTEN  0       128            0.0.0.0:22           0.0.0.0:*              
LISTEN  0       511                  *:80                 *:*              
LISTEN  0       128               [::]:22              [::]:*              
LISTEN  0       70                   *:33060              *:*              
LISTEN  0       151                  *:3306               *:*              
停止服务
[root@zyq ~]#: service mysqld stop
Shutting down MySQL.. SUCCESS!

用配置文件方式启动,停止服务
[root@zyq ~]#: cd /usr/lib/systemd/system
[root@zyq system]#: cp sshd.service mysql.service
[root@zyq system]#: vi mysql.service 
[root@zyq system]#: cat mysql.service 
[Unit]
Description=mysqld server daemon
After=network.target 

[Service]
Type=forking
ExecStart=service mysqld start
ExecStop=service mysqld stop
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
[root@zyq system]#: systemctl daemon-reload 
[root@zyq system]#: cd
[root@zyq ~]#: systemctl status mysql.service 
○ mysql.service - mysqld server daemon
     Loaded: loaded (/usr/lib/systemd/system/mysql.service; disabled; vend>
     Active: inactive (dead)

[root@zyq ~]#: ss -antl
State   Recv-Q  Send-Q   Local Address:Port    Peer Address:Port  Process  
LISTEN  0       128            0.0.0.0:22           0.0.0.0:*              
LISTEN  0       511                  *:80                 *:*              
LISTEN  0       128               [::]:22              [::]:*              
[root@zyq ~]#: systemctl start mysql.service 
[root@zyq ~]#: ss -antl
State   Recv-Q  Send-Q   Local Address:Port    Peer Address:Port  Process  
LISTEN  0       128            0.0.0.0:22           0.0.0.0:*              
LISTEN  0       511                  *:80                 *:*              
LISTEN  0       128               [::]:22              [::]:*              
LISTEN  0       70                   *:33060              *:*              
LISTEN  0       151                  *:3306               *:*              
[root@zyq ~]#: systemctl status mysql.service 
● mysql.service - mysqld server daemon
     Loaded: loaded (/usr/lib/systemd/system/mysql.service; disabled; vend>
     Active: active (running) since Tue 2023-12-05 17:52:41 CST; 14s ago
    Process: 32503 ExecStart=service mysqld start (code=exited, status=0/S>
   Main PID: 32524 (mysqld_safe)
      Tasks: 39 (limit: 48715)
     Memory: 370.6M
        CPU: 520ms
     CGroup: /system.slice/mysql.service
             ├─32524 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/o>
             └─32714 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysq>

Dec 05 17:52:40 zyq systemd[1]: Starting mysqld server daemon...
Dec 05 17:52:41 zyq service[32507]: Starting MySQL. SUCCESS!
Dec 05 17:52:41 zyq systemd[1]: Started mysqld server daemon.

设置开机自启
[root@zyq ~]#: systemctl enable mysql.service 
Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /usr/lib/systemd/system/mysql.service.
[root@zyq ~]#: systemctl status mysql.service 
● mysql.service - mysqld server daemon
     Loaded: loaded (/usr/lib/systemd/system/mysql.service; enabled; vendo>
     Active: active (running) since Tue 2023-12-05 17:52:41 CST; 2min 15s >
   Main PID: 32524 (mysqld_safe)
      Tasks: 38 (limit: 48715)
     Memory: 370.6M
        CPU: 1.075s
     CGroup: /system.slice/mysql.service
             ├─32524 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/o>
             └─32714 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysq>

Dec 05 17:52:40 zyq systemd[1]: Starting mysqld server daemon...
Dec 05 17:52:41 zyq service[32507]: Starting MySQL. SUCCESS!
Dec 05 17:52:41 zyq systemd[1]: Started mysqld server daemon.

重启检测
[root@zyq ~]#: reboot
[root@zyq ~]#: ss -antl
State   Recv-Q  Send-Q   Local Address:Port    Peer Address:Port  Process  
LISTEN  0       128            0.0.0.0:22           0.0.0.0:*              
LISTEN  0       128               ::]:22              [::]:*              
LISTEN  0       70                   *:33060              *:*              
LISTEN  0       151                  *:3306               *:*  
设置数据库密码
powershell 复制代码
使用初始化的密码登录
[root@zyq ~]#: mysql -uroot -p'n1O6QThtF;mu'

mysql> alter user 'root'@'localhost' identified with mysql_native_password by 'Pssword@_';
相关推荐
m0_7482448318 分钟前
StarRocks 排查单副本表
大数据·数据库·python
雨中rain22 分钟前
Linux -- 从抢票逻辑理解线程互斥
linux·运维·c++
C++忠实粉丝29 分钟前
Redis 介绍和安装
数据库·redis·缓存
Bessssss42 分钟前
centos日志管理,xiao整理
linux·运维·centos
s_yellowfish42 分钟前
Linux服务器pm2 运行chatgpt-on-wechat,搭建微信群ai机器人
linux·服务器·chatgpt
wmd1316430671244 分钟前
将微信配置信息存到数据库并进行调用
数据库·微信
豆是浪个44 分钟前
Linux(Centos 7.6)yum源配置
linux·运维·centos
vvw&1 小时前
如何在 Ubuntu 22.04 上安装 Ansible 教程
linux·运维·服务器·ubuntu·开源·ansible·devops
我一定会有钱1 小时前
【linux】NFS实验
linux·服务器
Ven%1 小时前
如何在防火墙上指定ip访问服务器上任何端口呢
linux·服务器·网络·深度学习·tcp/ip