01.二进制安装mysql7

二进制版本安装mysql

创建软件目录
mkdir -p /server/tools
cd /server/tools
yum install -y lrzsz
rz -E (5.7 软件)
[root@db01 tools]# ls
mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz

解压软件
tar xf ..
mkdir /application
mv .软件. /application/mysql

卸载mariadb
rpm -qa|grep mariadb && yum remove mariadb*

创建用户
useradd -s /sbin/nologin mysql

设置环境变量
[root@db01 tools]# vim /etc/profile
...
export PATH=/application/mysql/bin:$PATH
[root@db01 tools]# source /etc/profile
[root@db01 tools]# mysql -V
mysql  Ver 14.14 Distrib 5.7.20, for linux-glibc2.12 (x86_64) using  EditLine wrapper

创建数据路径并授权 
1.关机添加一块20g的新磁盘
2.格式化并挂载磁盘
[root@db01 ~]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0003899d

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2105343     1051648   83  Linux
/dev/sda2         2105344    41943039    19918848   8e  Linux LVM

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

[root@db01 ~]# mkfs.xfs /dev/sdb
[root@db01 ~]# mkdir /data
[root@db01 ~]# blkid
...
/dev/sdb: UUID="a2169939-ebe0-4973-acc1-4036b0d34272" TYPE="xfs" 

[root@db01 ~]#  vim /etc/fstab
...
UUID="a2169939-ebe0-4973-acc1-4036b0d34272" /data xfs defaults 0 0 
 
[root@db01 ~]# mount -a
[root@db01 ~]# df -h
...
/dev/sdb                  20G   33M   20G   1% /data

授权
[root@db01 ~]#  chown -R mysql.mysql /application/*
[root@db01 ~]# chown -R mysql.mysql /data

初始化数据(创建系统数据)
#5.6版本初始化命令:/application/mysql/scripts/mysql_install_d

#5.7版本
[root@db01 ~]# mkdir /data/mysql/data -p
[root@db01 ~]# chown -R mysql.mysql /data
[root@db01 ~]# mysqld --initialize --user=mysql --basedir=/application/mysql --datadir=/data/mysql/data
2021-10-24T02:31:03.732408Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-10-24T02:31:04.257917Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-10-24T02:31:04.330256Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-10-24T02:31:04.407210Z 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: 6f8d0611-3472-11ec-a847-000c29567ba5.
2021-10-24T02:31:04.409542Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-10-24T02:31:04.410931Z 1 [Note] A temporary password is generated for root@localhost: mOo%#=4pA-!a #临时密码

说明:
--initialize参数:
1.对于密码复杂度进行定制:12位,4种
2.密码过期时间:180
3.给root@locahost用户设置临时密码

--initialize-insecure参数:
无限制,无临时密码
\rm -rf /data/mysql/data/*
mysqld --initialize-insecure --user=mysql --basedir=/application/mysql --datadir=/data/mysql/data

如果报错要安装依赖包

配置文件 的准备

[root@db01 ~]# cat >/etc/my.cnf <<EOF
> [mysqld]
> user=mysql
> basedir=/application/mysql
> datadir=/data/mysql/data
> socket=/tmp/mysql.sock
> server_id=6
> [mysql]
> socket=/tmp/mysql.sock
> EOF

启动

两种方式
1.sys-v
[root@db01 ~]# cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@db01 ~]# service mysqld restart
 ERROR! MySQL server PID file could not be found!
Starting MySQL.Logging to '/data/mysql/data/db01.err'.
 SUCCESS!
 [root@db01 ~]# /etc/init.d/mysqld stop #停服务
Shutting down MySQL.. SUCCESS!

 2.system管理
 注意:sysv方式启动过的话,需提前关闭服务
 
cat >/etc/systemd/system/mysqld.service <<EOF 
 [Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=https://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/application/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
EOF

[root@db01 ~]# systemctl start mysqld

如何分析处理mysql数据库无法启动

查看日志
/data/mysql/data/主机名.err

可能情况
/etc/my.cnf 路径不对等
/tmp/mysql.sock文件修改过或删除过
数据目录权限不是mysql
参数改错了

管理员密码的设定

[root@db01 data]# mysqladmin -uroot -p password cdan@111
Enter password:  旧密码,如果没有初始密码,回车即可

忘记密码

1.关闭数据库
[root@db01 data]# systemctl stop mysqld

2.启动数据库到维护模式。跳过授权表、跳过远程登录
root@db01 data]# mysqld_safe --skip-grant-table --skip-networking &
posted @ 2021-10-24 11:40  小绵  阅读(40)  评论(0编辑  收藏  举报