二进制源码部署mysql8.0.35

二进制部署mysql8.0.35

创建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               *:*  

设置数据库密码
使用初始化的密码登录
[root@zyq ~]#: mysql -uroot -p'n1O6QThtF;mu'

mysql> alter user 'root'@'localhost' identified with mysql_native_password by 'Pssword@_';

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值