二进制安装MySQL

发布时间 2023-09-13 10:00:31作者: louvice

二进制安装MySQL

## 安装mysql

#添加用户组
[root@localhost ~]# groupadd mysql 
[root@localhost ~]# useradd -r -g mysql -s /sbin/nologin mysql
[root@localhost ~]# mkdir /soft/src -p && cd /soft/src

#赋予权限
[root@localhost src]# mkdir -p /var/run/mysqld && chown -R mysql:mysql /var/run/mysqld/
[root@localhost src]# rz -E
rz waiting to receive.
[root@localhost src]# tar -xf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz -C /soft/
[root@localhost src]# ln -s /soft/mysql-5.7.30-linux-glibc2.12-x86_64/ /soft/mysql
[root@localhost src]#  mkdir /soft/mysql/{mysql-file,data}
[root@localhost src]#  chown -R mysql.mysql /soft/mysql/

## 初始化数据库
[root@localhost src]#  /soft/mysql/bin/mysqld --initialize \
> --user=mysql --basedir=/soft/mysql \
> --datadir=/soft/mysql/data
2023-09-12T11:31:55.577334Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2023-09-12T11:31:55.761346Z 0 [Warning] InnoDB: New log files created, LSN=45790
2023-09-12T11:31:55.804213Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2023-09-12T11:31:55.871396Z 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: fa557dd1-515f-11ee-8e0b-000c29edb019.
2023-09-12T11:31:55.875867Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2023-09-12T11:31:56.565590Z 0 [Warning] CA certificate ca.pem is self signed.
2023-09-12T11:31:56.663291Z 1 [Note] A temporary password is generated for root@localhost: SNtk<rqq>78l

##修改配置文件
[root@localhost src]# mv /etc/my.cnf /etc/my.cnf_bak
[root@localhost src]# vim /etc/my.cnf
[mysqld]
basedir=/soft/mysql
datadir=/soft/mysql/data
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
socket=/tmp/mysql.sock

#加入systemd管理
[root@localhost src]# cp /soft/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost src]# chkconfig --add mysqld
[root@localhost src]#  chkconfig mysqld on
[root@localhost src]#  sed -i '/^basedir=/cbasedir=\/soft\/mysql' /etc/init.d/mysqld
[root@localhost src]#  sed -i '/^datadir=/cdatadir=\/soft\/mysql\/data' /etc/init.d/mysqld
[root@localhost src]#  /etc/init.d/mysqld start
Starting MySQL. SUCCESS! 

#添加系统变量
[root@localhost src]# echo "export PATH=$PATH:/soft/mysql/bin" >> /etc/profile
[root@localhost src]# source /etc/profile

#修改数据库密码
alter user root@'localhost' identified by '123456';