1. MySQL 5.7 binary deployment
1. Prepare the environment
Prepare a Centos 7.6 system with a minimum memory of 512. It is best to mount two disks, one as the system disk and the other as the MySQL data disk.
1. Modify hosts, close selinux, firewalld
hostnamectl set-hostname mysql01
sed -ri '/^SELINUX=/cSELINUX=disabled' /etc/selinux/config
systemctl stop firewalld && systemctl disable firewalld
2. Create a directory
#1.创建程序目录
mkdir /application
#2.创建存放软件包目录
mkdir tools
3. Format the data disk and mount it under /data
#1.格式化/dev/sdb磁盘
mkfs.xfs /dev/sdb
#2.mount挂载加入开机自启、每个UUID值不一样通过 blkid命令查看
echo "UUID=26390314-0703-4200-a181-0f8fdaf09368 /data xfs defaults 0 0 " >> /etc/fstab
#3.mount 挂载
#4.查看是否挂载情况
[root@mysql01 ~]# df -Th | grep "/data"
/dev/sdb xfs 20G 33M 20G 1% /data
2. Deploy MySQL 5.7 in binary mode
mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
download address https://downloads.mysql.com/archives/community/
1. Upload the binary package to the /tools directory and unzip it to the /application program directory
cd /tools && tar zxvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz -C /application/
cd /application/ && mv mysql-5.7.26-linux-glibc2.12-x86_64 mysql-5.7.26
2. The creation of the user handles the original environment
yum remove mariadb-libs-5.5.60-1.el7_5.x86_64 -y 或手动删除/etc/my.cn文件
rpm -qa |grep mariadb
useradd -s /sbin/nologin mysql
3. Set environment variables
echo 'PATH=/application/mysql-5.7.26/bin:$PATH' >> /etc/profile
source /etc/profile
4. Initialize the data
#1.创建数据目录并授权
mkdir /data/mysql/data -p && chown -R mysql.mysql /data
#2.初始化 (二选一)
mysqld --initialize --user=mysql --basedir=/application/mysql-5.7.26 --datadir=/data/mysql/data //有临时密码初始化
mysqld --initialize-insecure --user=mysql --basedir=/application/mysql-5.7.26 --datadir=/data/mysql/data //无临时密码初始化
5. Configure the my.cnf file
cat >/etc/my.cnf <<EOF
[mysqld]
user=mysql
basedir=/application/mysql-5.7.26
datadir=/data/mysql/data
socket=/tmp/mysql.sock
server_id=6
port=3306
log_error=/data/mysql/mysql.log
# log_bin=/data/mysql/mysql-bin
[mysql]
socket=/tmp/mysql.sock
EOF
6, start the database
#1.默认启动方式
[root@db01 ~]#cd /application/mysql/support-files/
[root@db01 support-files ]#./mysql.server start
#2.设置sys-v service启动
[root@db01 /etc/init.d]# cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@db01 /etc/init.d]# service mysqld restart
#3.设置systemd启动
注意: sysv方式启动过的话,需要先提前关闭,才能以下方式登录
cat >/etc/systemd/system/mysqld.service <<EOF
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://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-5.7.26/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
EOF
启动
systemctl start mysqld && systemctl enable mysqld
How to analyze and deal with the failure of the MySQL database to start
without updating PID similar error
View log:
Where?
/data/mysql/data/hostname.err
[ERROR] Context
Possible situation:
/etc/my.cnf path is not equal
/tmp/mysql.sock file has been modified or deleted
Data directory permissions are not mysql
parameters are corrected wrong
#报错
Starting MySQL.2020-09-01T07:32:45.953856Z mysqld_safe error: log-error set to '/data/mysql/mysql.log', however file don't exists. Create writable for user 'mysql'.
ERROR! The server quit without updating PID file (/data/mysql/data/sonarqube.pid).
解决
touch /data/mysql/mysql.log
chown -R mysql.mysql /data/mysql/mysql.log
Verification: netstat -anpt
7. Setting of administrator password (no temporary password when formatting)
[root@db01 ~]# mysqladmin -uroot -p password adminroot
Enter password: #此处直接回车