mysql5.7.22升级到mysql8.0.23升级步骤

现有环境信息:

mysql版本:

root@ho_test43[/root]#rpm -qa| grep mysql
mysql-community-embedded-5.7.22-1.el7.x86_64
mysql-community-libs-5.7.22-1.el7.x86_64
mysql-community-devel-5.7.22-1.el7.x86_64
mysql-community-common-5.7.22-1.el7.x86_64
mysql-community-embedded-devel-5.7.22-1.el7.x86_64
mysql-community-client-5.7.22-1.el7.x86_64
mysql-community-server-5.7.22-1.el7.x86_64
root@ho_test43[/root]#

操作系统:

root@ho_test43[/root]#cat /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core) 

升级目标版本:

mysql8.0.23

要求:

1、最少的停机时间。

2、现有库里面的数据不丢失。

升级思路

目前有两种升级思路

1、一是备份现有mysql配置文件/etc/my.cnf,然后卸载5.7.22的rpm包,安装mysql8.0.23的rpm包,然后启动mysql8.0.23的mysql服务,拉起数据库,在mysql8.0.16以上的版本,可以直接拉起mysqld服务,无需执行mysql_upgrate,在mysqld服务中会自动进行mysql_upgrate的更新。

卸载mysql 的rpm安装包:

rpm -qa | egrep -i "mysql|mariadb" |xargs rpm -e --nodeps

2、二是仍然备份现有mysql配置文件/etc/my.cnf,然后下载mysql通用linux版本,该压缩包解压后可以直接用来启动mysqld服务。停原mysql5.7.22服务,然后起mysql8.0.23服务。

目前我这边使用第二种方式。

升级步骤

1、下载mysql安装介质

下载最新版本mysql8.0.23

https://dev.mysql.com/downloads/mysql/

下载历史版本:

https://downloads.mysql.com/archives/community/

2、备份mysql配置文件/etc/my.cnf

现有mysql配置文件/etc/my.cnf

root@ho_test43[/root]#cat /etc/my.cnf20210308 
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid


###########
[client]
socket=/var/lib/mysql/mysql.sock
[mysqld]
server-id = 1
auto_increment_offset=3
auto_increment_increment=7
large_pages
log_timestamps=SYSTEM
innodb_numa_interleave=1
explicit_defaults_for_timestamp
transaction-isolation = READ-COMMITTED
log_bin_trust_function_creators = 1
datadir=/mysql/data
socket=/var/lib/mysql/mysql.sock
log-error=/mysql/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
log-bin=/mysql/bin_log/mysql-binlog
slow_query_log_file=/mysql/log/slow.log
general_log_file=/mysql/log/general.log
slow_query_log=1
log_slow_admin_statements=1
long_query_time=2
expire_logs_days=7
performance_schema = ON
character-set-server=utf8
collation-server=utf8_bin
skip-name-resolve
lower_case_table_names
skip-external-locking
key_buffer_size = 128M
max_allowed_packet = 16M
table_open_cache = 1024
table_open_cache_instances=4
sort_buffer_size = 8M
net_buffer_length = 8K
myisam_sort_buffer_size = 8M
max_connections = 2048
max_user_connections = 2000
query_cache_size = 0
query_cache_type = 0
tmp_table_size = 1024M
tmpdir=/mysql/tmp
max_heap_table_size = 1024M
innodb_log_files_in_group = 4
innodb_log_file_size = 1024M
innodb_undo_directory=/mysql/undo_tbls
innodb_undo_tablespaces=4
innodb_undo_log_truncate=on
innodb_flush_method= O_DIRECT
innodb_buffer_pool_size = 1G
innodb_buffer_pool_instances = 1
innodb_buffer_pool_chunk_size=128MB
innodb_log_buffer_size = 64M
innodb_file_per_table
innodb_data_file_path=ibdata1:1000M:autoextend
innodb_flush_log_at_trx_commit = 2
sync_binlog = 1
binlog-group-commit-sync-delay=10
binlog_group_commit_sync_no_delay_count=5
innodb_lock_wait_timeout = 50
innodb_rollback_on_timeout = ON
innodb_io_capacity = 2000
innodb_read_io_threads = 2
innodb_write_io_threads  = 2
innodb_thread_concurrency = 0
innodb_sync_spin_loops = 200
innodb_spin_wait_delay = 6
innodb_status_file = 1
innodb_doublewrite=1
innodb_max_dirty_pages_pct = 75
innodb_support_xa=1
innodb_checksum_algorithm=crc32
innodb_adaptive_hash_index = 1
innodb_purge_threads=4
innodb_use_native_aio = 1
innodb_autoinc_lock_mode = 2
innodb_change_buffering = all
symbolic-links=0
binlog_format=ROW
default_storage_engine=InnoDB
lower_case_table_names=1
max_connections=3500
root@ho_test43[/root]#

备份该配置文件:

cp /etc/my.cnf /etc/my.cnf20210308

3、上传并解压mysql8.0.23安装介质

cd /usr/local/

xz -d mysql-8.0.23-linux-glibc2.17-x86_64-minimal.tar.xz

tar -xvf mysql-8.0.23-linux-glibc2.17-x86_64-minimal.tar

mv mysql-8.0.23-linux-glibc2.17-x86_64-minimal mysql8

chown -R mysql.mysql /usr/local/mysql8

4、配置内核参数等(该步骤一般生产环境可以忽略)

 因为该环境是所内测试环境,所以有些内核参数并没有正常去按标准配置。下面我提供了一个脚本,可以标准化配置该操作系统环境。

执行该脚本的先决条件

该脚本需要在执行之前配置好本地yum源(挂载在/mnt下即可,该部分内容就是脚本的最开始备注释掉的内容)。

如果需要配置chronyd时间同步服务,请提前确定好时间同步服务器的ip地址,在脚本中需要更改该ip。脚本中位置,直接搜索文本 "10.xxx.xxx.xxx" 即可找到。

该脚本在redhat7.x和centos7.x下运行良好,只需更改脚本中的"centos.pool.ntp.org"为"redhat.pool.ntp.org"即可。

#!/bin/bash

#mount -o loop /soft/CentOS-7-x86_64-Everything-1810.iso /mnt/
#
#cd /etc/yum.repos.d
#mkdir -p backup/
#mv *.repo /etc/yum.repos.d/backup/
##vi /etc/yum.repos.d/file.repo
#echo "[centos7-Server]">> /etc/yum.repos.d/file.repo
#echo "name=centos7-Server">> /etc/yum.repos.d/file.repo
#echo "baseurl=file:///mnt">> /etc/yum.repos.d/file.repo
#echo "enabled=1">> /etc/yum.repos.d/file.repo
#echo "gpgcheck=0">> /etc/yum.repos.d/file.repo
#
#yum clean all
#
#yum makecache 


yum -y install aide
yum -y install audit
yum -y install bind-utils
yum -y install expect
yum -y install ipa-client
yum -y install ksh
yum -y install mailx
yum -y install man-db
yum -y install mlocate
yum -y install nmap-ncat
yum -y install net-snmp
yum -y install ntpdate
yum -y install openssh-clients
yum -y install openssh-server
yum -y install parted
yum -y install perl
yum -y install postfix
yum -y install screen
yum -y install setroubleshoot-server
yum -y install sudo
yum -y install tcpdump
yum -y install vim-enhanced
yum -y install wget
yum -y install libstdc++.i686
yum -y install glibc.i686
yum -y install psmisc.x86_64
yum -y install net-tools.x86_64
yum -y install unzip.x86_64
yum -y install gcc.x86_64
yum -y install gcc-c++.x86_64
yum -y install lsof.x86_64
yum -y install bc.x86_64
yum -y install xfsdump
yum -y install chrony
yum -y install dos2unix
yum -y install nmap       

rpm -q aide \
audit \
bind-utils \
expect \
ipa-client \
ksh \
mailx \
man-db \
mlocate \
nmap-ncat \
net-snmp \
ntpdate \
openssh-clients \
openssh-server \
parted \
perl \
postfix \
screen \
setroubleshoot-server \
sudo \
tcpdump \
vim-enhanced \
wget \
libstdc++.i686 \
glibc.i686 \
psmisc.x86_64 \
net-tools.x86_64 \
unzip.x86_64 \
gcc.x86_64 \
gcc-c++.x86_64 \
lsof.x86_64 \
bc.x86_64 \
xfsdump \
chrony \
dos2unix \
nmap


#yum -y install device-mapper-multipath
#
#if [ ! -f /etc/multipath.conf ];then 
#	cp /usr/share/doc/device-mapper-multipath-0.4.9/multipath.conf /etc/multipath.conf
#fi 
#systemctl start multipathd
#
#systemctl enable multipathd


anum=`cat -n /etc/profile |grep "PS1"|grep -v "#" |awk '{print $1}'|wc -l`
if [ $anum -eq 0 ];then 
	echo "# set PS1 environment" >>/etc/profile
	echo "if [ \$UID -eq 0 ]; then" >>/etc/profile
	echo "    export PS1=\$LOGNAME@\`hostname\`['\$PWD']#" >>/etc/profile
	echo "else" >>/etc/profile
	echo "    export PS1=\$LOGNAME@\`hostname\`['\$PWD']\$" >>/etc/profile
	echo "fi" >>/etc/profile
fi 

anum=`cat -n /etc/profile |grep "HISTTIMEFORMAT"|grep -v "#" |awk '{print $1}'|wc -l`
if [ $anum -eq 0 ];then 
	echo "# set histimeformat environment" >>/etc/profile
	echo "export HISTTIMEFORMAT='%F %T '" >>/etc/profile
fi 

anum=`cat -n /etc/profile |grep "coredump_filter"|grep -v "#" |awk '{print $1}'|wc -l`
if [ $anum -eq 0 ];then 
	echo "# set CORE NO SHM" >>/etc/profile
	echo "echo 0x1 > /proc/self/coredump_filter" >>/etc/profile
fi 

source /etc/profile

anum=`cat -n /etc/selinux/config |grep "SELINUX"|grep -v "#" |awk '{print $1}'|wc -l`
if [ $anum -eq 0 ]; then
	echo "SELINUX=disabled" >> /etc/selinux/config
else
	sed -i "`cat -n /etc/selinux/config |grep "SELINUX="|grep -v "#" |awk '{print $1}'`c SELINUX=disabled" /etc/selinux/config
fi


setenforce 0

getenforce 


systemctl stop firewalld

systemctl disable firewalld

systemctl stop NetworkManager
systemctl disable NetworkManager


if [ ! -f /boot/grub2/grub.cfg.bak ];then 
	cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg.bak
fi 
if [ ! -f /etc/default/grub.bak ]; then 
	cp /etc/default/grub /etc/default/grub.bak
fi 
grub_cmdlinux_linux=`cat /etc/default/grub |grep GRUB_CMDLINE_LINUX`

echo $grub_cmdlinux_linux

new_str=`echo $grub_cmdlinux_linux | sed 's/\"\(\w*$\)/ transparent_hugepage=never numa=off\"\1/g'`

n_count=`cat /etc/default/grub |grep "GRUB_CMDLINE_LINUX" |grep "transparent_hugepage"|wc -l`
if [ $n_count -eq 0 ]; then
	anum=`cat -n /etc/default/grub |grep 'GRUB_CMDLINE_LINUX'|grep -v '#'|awk '{print $1}'|wc -l`
	if [ $anum -eq 0 ]; then
		echo $new_str >> /etc/default/grub
	else
		sed -i "`cat -n /etc/default/grub |grep 'GRUB_CMDLINE_LINUX'|grep -v '#'|awk '{print $1}'`c $new_str" /etc/default/grub
	fi
	
	grub2-mkconfig -o /boot/grub2/grub.cfg
fi
echo "1.............."
anum=`cat -n /etc/rc.d/rc.local |grep "transparent_hugepage"|grep -v "#" |awk '{print $1}'|wc -l`
if [ $anum -eq 0 ];then 
	echo "# Disable Transparent HugePages" >> /etc/rc.d/rc.local
	echo "if test -f /sys/kernel/mm/transparent_hugepage/enabled; then" >> /etc/rc.d/rc.local
	echo "    echo never > /sys/kernel/mm/transparent_hugepage/enabled" >> /etc/rc.d/rc.local
	echo "fi" >> /etc/rc.d/rc.local
	echo "if test -f /sys/kernel/mm/transparent_hugepage/defrag; then" >> /etc/rc.d/rc.local
	echo "    echo never > /sys/kernel/mm/transparent_hugepage/defrag" >> /etc/rc.d/rc.local
	echo "fi" >> /etc/rc.d/rc.local
	chmod +x /etc/rc.d/rc.local
fi 

anum=`cat -n /etc/security/limits.conf |grep "Zsmart"|awk '{print $1}'|wc -l`
if [ $anum -eq 0 ];then 
	echo "# For Zsmart" >>/etc/security/limits.conf
	echo "* soft core 10485760" >>/etc/security/limits.conf
	echo "* hard core 10485760" >>/etc/security/limits.conf
fi 

#/etc/security/limits.d/20-nproc.conf
anum=`cat -n /etc/security/limits.d/20-nproc.conf |grep "Zsmart"|awk '{print $1}'|wc -l`
if [ $anum -eq 0 ];then 
	echo "# For Zsmart">>/etc/security/limits.d/20-nproc.conf
	echo "* soft nofile 65536">>/etc/security/limits.d/20-nproc.conf
	echo "* hard nofile 65536">>/etc/security/limits.d/20-nproc.conf
	echo "* soft nproc 65536">>/etc/security/limits.d/20-nproc.conf
	echo "* hard nproc 65536">>/etc/security/limits.d/20-nproc.conf
	echo "root soft nproc unlimited">>/etc/security/limits.d/20-nproc.conf
fi 

#/etc/security/limits.conf
anum=`cat -n /etc/security/limits.conf |grep "soft nofile 65536"|awk '{print $1}'|wc -l`
if [ $anum -eq 0 ];then 
	echo "# For Zsmart" >>/etc/security/limits.conf
	echo "* soft nofile 65536" >>/etc/security/limits.conf
	echo "* hard nofile 65536" >>/etc/security/limits.conf
	echo "* soft nproc 65536" >>/etc/security/limits.conf
	echo "* hard nproc 65536" >>/etc/security/limits.conf
	echo "* soft stack 10240" >>/etc/security/limits.conf
fi 

#/etc/pam.d/login
anum=`cat -n /etc/pam.d/login |grep "pam_limits.so"|grep -v "#"|awk '{print $1}'|wc -l`
if [ $anum -eq 0 ];then 
	echo "# Enbale limit setting">>/etc/pam.d/login
	echo "session required pam_limits.so" >> /etc/pam.d/login
fi

echo "22.........................."
ncount=`cat /etc/sysctl.conf |grep "kernel.shmmax" |grep -v "#"|wc -l`
if [ $ncount -eq 0 ];then
	echo "444.............."
	memnum=`free -m|grep Mem |awk '{print $2}'`
	echo "555.............."
	nshmmax=`expr $memnum \* 1024 \* 1024`
	echo "666.............."
	nshmall=`expr $nshmmax / 4096`
	echo "777.............."
	mem1=`free -g|grep Mem |awk '{print $2}'`
	echo "888.............."
	v_min_free_kbytes=2097152
	echo "999.............."
	if [ $mem1 -lt 64 ];then 
		 v_min_free_kbytes=1048576
	elif [ $mem1 -ge 64 ] && [ $mem1 -lt 128 ] ; then 
		 v_min_free_kbytes=2097152
	else
		 v_min_free_kbytes=3145728
	fi
	echo "aaaa.............."
	echo "##########Shared Memory###############" >>/etc/sysctl.conf
	echo "kernel.shmmax=$nshmmax">>/etc/sysctl.conf
	echo "kernel.shmmni=4096">>/etc/sysctl.conf
	echo "kernel.shmall=$nshmall">>/etc/sysctl.conf
	echo "##########Semaphore Arrays############">>/etc/sysctl.conf
	echo "kernel.sem=6144 50331648 4096 8192">>/etc/sysctl.conf
	echo "##########open file###################">>/etc/sysctl.conf
	echo "fs.file-max=6815744">>/etc/sysctl.conf
	echo "##########aio#########################">>/etc/sysctl.conf
	echo "fs.aio-max-nr=3145728">>/etc/sysctl.conf
	echo "##########network#####################">>/etc/sysctl.conf
	echo "net.ipv4.icmp_echo_ignore_broadcasts=1">>/etc/sysctl.conf
	echo "net.ipv4.icmp_ignore_bogus_error_responses=1">>/etc/sysctl.conf
	echo "net.ipv4.conf.all.rp_filter=1">>/etc/sysctl.conf
	echo "net.ipv4.conf.default.rp_filter=1">>/etc/sysctl.conf
	echo "net.ipv4.tcp_syncookies=1">>/etc/sysctl.conf
	echo "net.ipv4.tcp_fin_timeout=30">>/etc/sysctl.conf
	echo "net.ipv4.tcp_keepalive_time=1500">>/etc/sysctl.conf
	echo "net.ipv4.tcp_keepalive_probes=5">>/etc/sysctl.conf
	echo "net.ipv4.tcp_keepalive_intvl=60">>/etc/sysctl.conf
	echo "net.ipv4.tcp_window_scaling=1">>/etc/sysctl.conf
	echo "net.core.rmem_default=262144">>/etc/sysctl.conf
	echo "net.core.wmem_default=262144">>/etc/sysctl.conf
	echo "net.core.rmem_max=4194304">>/etc/sysctl.conf
	echo "net.core.wmem_max=4194304">>/etc/sysctl.conf
	echo "net.ipv4.tcp_rmem=8192 262144 4194304">>/etc/sysctl.conf
	echo "net.ipv4.tcp_wmem=8192 262144 4194304">>/etc/sysctl.conf
	echo "net.ipv4.ip_local_port_range=9000 65500">>/etc/sysctl.conf
	echo "##########CORE######################">>/etc/sysctl.conf
	echo "kernel.core_uses_pid=1">>/etc/sysctl.conf
	echo "##########Message Queues##############">>/etc/sysctl.conf
	echo "kernel.msgmax=655360">>/etc/sysctl.conf
	echo "kernel.msgmni=4096">>/etc/sysctl.conf
	echo "kernel.msgmnb=1024000">>/etc/sysctl.conf
	echo "##########vm config###################">>/etc/sysctl.conf
	echo "vm.min_free_kbytes=$v_min_free_kbytes">>/etc/sysctl.conf
	echo "vm.vfs_cache_pressure=200">>/etc/sysctl.conf
	echo "vm.swappiness=10">>/etc/sysctl.conf
fi

echo "333............................"
sysctl -p


systemctl status vsftpd

yum -y install ftp vsftpd
anum=`cat -n /etc/vsftpd/ftpusers |grep "root"|grep -v "#" |awk '{print $1}'|wc -l`
if [ $anum -eq 0 ]; then
	echo  "nothing need to do."
else
	sed -i "`cat -n /etc/vsftpd/ftpusers |grep "root"|grep -v "#" |awk '{print $1}'`c #root" /etc/vsftpd/ftpusers
fi
anum=`cat -n /etc/vsftpd/user_list |grep "root"|grep -v "#" |awk '{print $1}'|wc -l`
if [ $anum -eq 0 ]; then
	echo  "nothing need to do."
else
	sed -i "`cat -n /etc/vsftpd/user_list |grep "root"|grep -v "#" |awk '{print $1}'`c #root" /etc/vsftpd/user_list
fi

anum=`cat -n /etc/vsftpd/vsftpd.conf |grep "anonymous_enable"|grep -v "#" |awk '{print $1}'|wc -l`
if [ $anum -eq 0 ]; then
	echo  "anonymous_enable=NO">> /etc/vsftpd/vsftpd.conf
else
	sed -i "`cat -n /etc/vsftpd/vsftpd.conf |grep "anonymous_enable"|grep -v "#" |awk '{print $1}'`c anonymous_enable=NO" /etc/vsftpd/vsftpd.conf
fi

anum=`cat -n /etc/vsftpd/vsftpd.conf |grep "write_enable"|grep -v "#" |awk '{print $1}'|wc -l`
if [ $anum -eq 0 ]; then
	echo  "write_enable=YES">> /etc/vsftpd/vsftpd.conf
else
	sed -i "`cat -n /etc/vsftpd/vsftpd.conf |grep "write_enable"|grep -v "#" |awk '{print $1}'`c write_enable=YES" /etc/vsftpd/vsftpd.conf
fi

anum=`cat -n /etc/vsftpd/vsftpd.conf |grep "local_enable"|grep -v "#" |awk '{print $1}'|wc -l`
if [ $anum -eq 0 ]; then
	echo  "local_enable=YES">> /etc/vsftpd/vsftpd.conf
else
	sed -i "`cat -n /etc/vsftpd/vsftpd.conf |grep "local_enable"|grep -v "#" |awk '{print $1}'`c local_enable=YES" /etc/vsftpd/vsftpd.conf
fi

anum=`cat -n /etc/vsftpd/vsftpd.conf |grep "ascii_upload_enable"|grep -v "#" |awk '{print $1}'|wc -l`
if [ $anum -eq 0 ]; then
	echo  "ascii_upload_enable=YES">> /etc/vsftpd/vsftpd.conf
else
	sed -i "`cat -n /etc/vsftpd/vsftpd.conf |grep "ascii_upload_enable"|grep -v "#" |awk '{print $1}'`c ascii_upload_enable=YES" /etc/vsftpd/vsftpd.conf
fi

anum=`cat -n /etc/vsftpd/vsftpd.conf |grep "ascii_download_enable"|grep -v "#" |awk '{print $1}'|wc -l`
if [ $anum -eq 0 ]; then
	echo  "ascii_download_enable=YES">> /etc/vsftpd/vsftpd.conf
else
	sed -i "`cat -n /etc/vsftpd/vsftpd.conf |grep "ascii_download_enable"|grep -v "#" |awk '{print $1}'`c ascii_download_enable=YES" /etc/vsftpd/vsftpd.conf
fi

anum=`cat -n /etc/vsftpd/vsftpd.conf |grep "use_localtime"|grep -v "#" |awk '{print $1}'|wc -l`
if [ $anum -eq 0 ]; then
	echo  "use_localtime=YES">> /etc/vsftpd/vsftpd.conf
else
	sed -i "`cat -n /etc/vsftpd/vsftpd.conf |grep "use_localtime"|grep -v "#" |awk '{print $1}'`c use_localtime=YES" /etc/vsftpd/vsftpd.conf
fi

systemctl restart vsftpd

##anum=`cat -n /etc/hosts |grep "10.119.193"|grep -v "#" |awk '{print $1}'|wc -l`
##if [ $anum -eq 0 ];then
##	echo "10.119.193.1   edr-app01" >>/etc/hosts
##	echo "10.119.193.2   edr-app02" >>/etc/hosts
##	echo "10.119.193.3   edr-app03" >>/etc/hosts
##	echo "10.119.193.4   edr-app04" >>/etc/hosts
##	echo "10.119.193.5   edr-app05" >>/etc/hosts
##	echo "10.119.193.6   edr-app06" >>/etc/hosts
##	echo "10.119.193.7   edr-app07" >>/etc/hosts
##	echo "10.119.193.8   edr-app08" >>/etc/hosts
##	echo "10.119.193.9   edr-app09" >>/etc/hosts
##fi 


if [ ! -f /etc/rsyslog.conf.bak ];then 
	cp /etc/rsyslog.conf /etc/rsyslog.conf.bak
fi 

a=`cat -n /etc/rsyslog.conf|grep "RULES"|awk '{print $1}'`
b=`expr $a + 1`

anum=`cat -n /etc/rsyslog.conf |grep "umask 0022"|grep -v "#" |awk '{print $1}'|wc -l`
if [ $anum -eq 0 ]; then
  echo "# set messages privilege">> /etc/rsyslog.conf
	echo  "\$umask 0022">> /etc/rsyslog.conf
else
	sed -i "`cat -n /etc/rsyslog.conf |grep "umask 0022"|grep -v "#" |awk '{print $1}'`c \$umask 0022" /etc/rsyslog.conf
fi

cp /var/log/messages /var/log/messages.bak
rm -rf /var/log/messages

systemctl restart rsyslog



#########################################begin new#########################################
echo "# LANG Tuning" >>/etc/profile
echo "export LANG=en_US.UTF-8" >>/etc/profile

anum=`cat -n /etc/chrony.conf |grep "0.centos.pool.ntp.org"|grep -v "#" |awk '{print $1}'|wc -l`
if [ $anum -eq 0 ]; then
	echo  "done...."
else
	sed -i "`cat -n /etc/chrony.conf |grep "0.centos.pool.ntp.org"|grep -v "#" |awk '{print $1}'`c #server 0.centos.pool.ntp.org iburst" /etc/chrony.conf
fi

anum=`cat -n /etc/chrony.conf |grep "1.centos.pool.ntp.org"|grep -v "#" |awk '{print $1}'|wc -l`
if [ $anum -eq 0 ]; then
	echo  "done...."
else
	sed -i "`cat -n /etc/chrony.conf |grep "1.centos.pool.ntp.org"|grep -v "#" |awk '{print $1}'`c #server 1.centos.pool.ntp.org iburst" /etc/chrony.conf
fi

anum=`cat -n /etc/chrony.conf |grep "2.centos.pool.ntp.org"|grep -v "#" |awk '{print $1}'|wc -l`
if [ $anum -eq 0 ]; then
	echo  "done...."
else
	sed -i "`cat -n /etc/chrony.conf |grep "2.centos.pool.ntp.org"|grep -v "#" |awk '{print $1}'`c #server 2.centos.pool.ntp.org iburst" /etc/chrony.conf
fi

anum=`cat -n /etc/chrony.conf |grep "3.centos.pool.ntp.org"|grep -v "#" |awk '{print $1}'|wc -l`
if [ $anum -eq 0 ]; then
	echo  "done...."
else
	sed -i "`cat -n /etc/chrony.conf |grep "3.centos.pool.ntp.org"|grep -v "#" |awk '{print $1}'`c #server 3.centos.pool.ntp.org iburst" /etc/chrony.conf
fi

echo "server 10.xxx.xxx.xxx iburst" >>/etc/chrony.conf 

systemctl restart chronyd
systemctl enable chronyd


ncount=`cat /etc/sysctl.conf |grep "kernel.shmmax" |grep -v "#"|wc -l`

	echo "444.............."
	memnum=`free -m|grep Mem |awk '{print $2}'`
	echo "555.............."
	nshmmax=`expr $memnum \* 1024 \* 1024`
	echo "666.............."
	nshmall=`expr $nshmmax / 4096`
	echo "777.............."
	mem1=`free -g|grep Mem |awk '{print $2}'`
	echo "888.............."
	v_min_free_kbytes=2097152
	echo "999.............."
	if [ $mem1 -lt 64 ];then 
		 v_min_free_kbytes=1048576
	elif [ $mem1 -ge 64 ] && [ $mem1 -lt 128 ] ; then 
		 v_min_free_kbytes=2097152
	else
		 v_min_free_kbytes=3145728
	fi
	echo "aaaa.............."
	
	anum=`cat -n /etc/sysctl.conf |grep "kernel.shmmax"|grep -v "#" |awk '{print $1}'|wc -l`
	if [ $anum -eq 0 ]; then
		echo "kernel.shmmax=$nshmmax">>/etc/sysctl.conf
	else
		sed -i "`cat -n /etc/sysctl.conf |grep "kernel.shmmax"|grep -v "#" |awk -v nshmmax="$nshmmax" '{print $1}'`c kernel.shmmax=$nshmmax" /etc/sysctl.conf
	fi
	
	anum=`cat -n /etc/sysctl.conf |grep "kernel.shmall"|grep -v "#" |awk '{print $1}'|wc -l`
	if [ $anum -eq 0 ]; then
		echo "kernel.shmall=$nshmall">>/etc/sysctl.conf
	else
		sed -i "`cat -n /etc/sysctl.conf |grep "kernel.shmall"|grep -v "#" |awk -v nshmall="$nshmall" '{print $1}'`c kernel.shmall=$nshmall" /etc/sysctl.conf
	fi
	
	anum=`cat -n /etc/sysctl.conf |grep "vm.min_free_kbytes"|grep -v "#" |awk '{print $1}'|wc -l`
	if [ $anum -eq 0 ]; then
		echo "vm.min_free_kbytes=$v_min_free_kbytes">>/etc/sysctl.conf
	else
		sed -i "`cat -n /etc/sysctl.conf |grep "vm.min_free_kbytes"|grep -v "#" |awk -v v_min_free_kbytes="$v_min_free_kbytes" '{print $1}'`c vm.min_free_kbytes=$v_min_free_kbytes" /etc/sysctl.conf
	fi

systemctl restart vsftpd
systemctl enable vsftpd


mkdir -p /var/log/cmdlog
chmod -R 777 /var/log/cmdlog

echo "# Record logging and command Tuning" >>/etc/profile
echo 'export PROMPT_COMMAND=@{ z=`history 1 | { read x y; echo $y; }`; echo -n $z ::; who am i; } >> /var/log/cmdlog/`id -un`_`who am i 2>/dev/null | awk -F[\(\)] "{if(\\$2)print \\$2;else print \"local\"}"`_`date +%Y%m%d`.log@'| sed "s/@/'/g"  >>/etc/profile
echo "readonly PROMPT_COMMAND" >>/etc/profile








echo "# Other Kernel Tuning" >> /etc/sysctl.conf
echo "kernel.hung_task_timeout_secs = 120" >> /etc/sysctl.conf
echo "kernel.sysrq=1" >> /etc/sysctl.conf
echo "# FS Tuning" >> /etc/sysctl.conf
echo "# VM Tuning" >> /etc/sysctl.conf
echo "vm.drop_caches=1" >> /etc/sysctl.conf
echo "vm.max_map_count=655360" >> /etc/sysctl.conf
echo "vm.dirty_writeback_centisecs=500" >> /etc/sysctl.conf
echo "vm.overcommit_memory=0" >> /etc/sysctl.conf

	memnum=`free -m|grep Mem |awk '{print $2}'`
	echo "555.............."
	nshmmax=`expr $memnum \* 1024 \* 1024`
	echo "666.............."
	nshmall=`expr $nshmmax / 4096`
	echo "777.............."
	mem1=`free -g|grep Mem |awk '{print $2}'`
	
v_dirty_ratio=40
v_dirty_background_ratio=20
	echo "aaaaaaaaa.............."
	if [ $mem1 -le 128 ];then 
		 v_dirty_ratio=40
		 v_dirty_background_ratio=20
	elif [ $mem1 -gl 128 ] && [ $mem1 -lt 256 ] ; then 
		 v_dirty_ratio=30
		 v_dirty_background_ratio=15
	elif [ $mem1 -ge 256 ] && [ $mem1 -lt 384 ] ; then 
		 v_dirty_ratio=20
		 v_dirty_background_ratio=10
	elif [ $mem1 -ge 384 ] && [ $mem1 -lt 512 ] ; then 
		 v_dirty_ratio=15
		 v_dirty_background_ratio=8
	elif [ $mem1 -ge 512 ] && [ $mem1 -lt 867 ] ; then 
		 v_dirty_ratio=10
		 v_dirty_background_ratio=5
	elif [ $mem1 -ge 867 ] && [ $mem1 -lt 1024 ] ; then 
		 v_dirty_ratio=7
		 v_dirty_background_ratio=4
	else
		 v_dirty_ratio=5
		 v_dirty_background_ratio=3
	fi
	
echo "vm.dirty_ratio=$v_dirty_ratio" >> /etc/sysctl.conf
echo "vm.dirty_background_ratio=$v_dirty_background_ratio" >> /etc/sysctl.conf


echo "# net.ipv4 Tuning" >> /etc/sysctl.conf
echo "net.ipv4.ip_forward=0" >> /etc/sysctl.conf
echo "net.ipv4.conf.all.send_redirects=0" >> /etc/sysctl.conf
echo "net.ipv4.conf.default.send_redirects=0" >> /etc/sysctl.conf
echo "net.ipv4.conf.all.accept_source_route=0" >> /etc/sysctl.conf
echo "net.ipv4.conf.default.accept_source_route=0" >> /etc/sysctl.conf
echo "net.ipv4.conf.all.accept_redirects=0" >> /etc/sysctl.conf
echo "net.ipv4.conf.default.accept_redirects=0" >> /etc/sysctl.conf
echo "net.ipv4.conf.all.secure_redirects=0" >> /etc/sysctl.conf
echo "net.ipv4.conf.default.secure_redirects=0" >> /etc/sysctl.conf
echo "net.ipv4.tcp_rmem=32768 436600 16777216" >> /etc/sysctl.conf
echo "net.ipv4.tcp_wmem=8192 436600 16777216" >> /etc/sysctl.conf
echo "# net.ipv6 Tuning" >> /etc/sysctl.conf
echo "net.ipv6.conf.all.disable_ipv6=1" >> /etc/sysctl.conf
echo "net.ipv6.conf.default.disable_ipv6=1" >> /etc/sysctl.conf
echo "net.ipv6.conf.lo.disable_ipv6=1" >> /etc/sysctl.conf
echo "net.ipv6.conf.default.accept_ra=0" >> /etc/sysctl.conf
echo "net.ipv6.conf.all.accept_ra=0" >> /etc/sysctl.conf
echo "net.ipv6.conf.default.accept_redirects=0" >> /etc/sysctl.conf
echo "net.ipv6.conf.all.accept_redirects=0" >> /etc/sysctl.conf
echo "# net.core Tuning" >> /etc/sysctl.conf
echo "net.core.rmem_default=8388608" >> /etc/sysctl.conf
echo "net.core.rmem_max=16777216" >> /etc/sysctl.conf
echo "net.core.wmem_default=8388608" >> /etc/sysctl.conf
echo "net.core.wmem_max=16777216" >> /etc/sysctl.conf
echo "net.core.netdev_max_backlog=32768" >> /etc/sysctl.conf
echo "net.core.somaxconn=32768" >> /etc/sysctl.conf
echo "kernel.panic_on_oops=1">>/etc/sysctl.conf 


echo "`cat /etc/sysconfig/network-scripts/ifcfg-ens192|grep IPADDR|cut -d = -f 2`     `hostname`">> /etc/hosts

echo "# CORE Tuning" >>/etc/security/limits.d/20-nproc.conf 
echo "*          soft     core       10485760" >>/etc/security/limits.d/20-nproc.conf 
echo "*          hard     core       10485760" >>/etc/security/limits.d/20-nproc.conf 


echo "*          soft     msgqueue  1048576">> /etc/security/limits.conf
echo "*          hard     msgqueue  1048576">> /etc/security/limits.conf

sysctl -p

source /etc/profile

#umount /mnt
#sleep 3
#mount -o loop /soft/CentOS-7-x86_64-Everything-1810.iso /mnt

#cd /etc/yum.repos.d/
#mv `ls new*.repo` `ls new*.repo`_bak

#yum clean all
#yum makecache

yum -y install aide \
audit \
bind-utils \
expect \
ipa-client \
ksh \
mailx \
man-db \
mlocate \
nmap-ncat \
net-snmp \
ntpdate \
openssh-clients \
openssh-server \
parted \
perl \
postfix \
screen \
setroubleshoot-server \
sudo \
sysstat \
tcpdump \
vim-enhanced \
wget \
libstdc++.i686 \
glibc.i686 \
psmisc \
net-tools \
unzip \
gcc \
gcc-c++ \
lsof \
bc \
xfsdump \
chrony \
dos2unix \
nmap \
telnet \
genisoimage \
iotop \
lm_sensors \
perl-Switch \
createrepo \
dstat \
smartmontools \
pciutils \
pciutils-libs \
openssl \
openssl-devel 


5、全备份数据库

mysql -e "show databases;" -uroot -p | grep -Ev "Database|information_schema|mysql|test|performance_schema|sys" | xargs mysqldump -uroot -p --databases > /mysqldump/data-for-upgrade8.0.23.sql

此命令是将除information_schema|mysql|test|performance_schema|sys库之外的数据全部导出到/mysqldump/data-for-upgrade8.0.23.sql

6、修改配置文件/etc/my.cnf

直接使用之前mysql5.7.22的配置文件/etc/my.cnf启动mysql8.0.23,因为在8.0中,有些在5.7中的参数现在不支持了,有些参数是更改了支持的取值。

对原有5.7的配置文件,新增如下配置mysql8.0的配置项:

#for8.0
sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
character-set-server = utf8
collation_server = utf8_general_ci
basedir = /usr/local/mysql8
skip_ssl
default_authentication_plugin = mysql_native_password

在mysql8.0中不支持的参数,需要注释掉,否则启动的时候会报下面的这些错误:

参数1:

query_cache_size

不注释报错:

2021-03-08T17:02:35.549906+08:00 0 [ERROR] [MY-000067] [Server] unknown variable 'query_cache_size=0'.
2021-03-08T17:02:35.552751+08:00 0 [ERROR] [MY-010119] [Server] Aborting
2021-03-08T17:02:36.868073+08:00 0 [Warning] [MY-011068] [Server] The syntax 'validate password plugin' is deprecated and will be removed in a future release. Please use validate_password component instead.
2021-03-08T17:02:37.938586+08:00 0 [System] [MY-010910] [Server] /usr/local/mysql8/bin/mysqld: Shutdown complete (mysqld 8.0.23)  MySQL Community Server - GPL.

 参数2:

query_cache_type

不注释报错:

2021-03-08T20:32:47.736499+08:00 0 [ERROR] [MY-000067] [Server] unknown variable 'query_cache_type=0'.
2021-03-08T20:32:47.737122+08:00 0 [ERROR] [MY-010119] [Server] Aborting
2021-03-08T20:32:48.671865+08:00 0 [Warning] [MY-011068] [Server] The syntax 'validate password plugin' is deprecated and will be removed in a future release. Please use validate_password component instead.
2021-03-08T20:32:49.281809+08:00 0 [System] [MY-010910] [Server] /usr/local/mysql8/bin/mysqld: Shutdown complete (mysqld 8.0.23)  MySQL Community Server - GPL.

参数3:

innodb_support_xa

不注释报错:

2021-03-08T20:39:11.302234+08:00 0 [ERROR] [MY-000067] [Server] unknown variable 'innodb_support_xa=1'.
2021-03-08T20:39:11.302942+08:00 0 [ERROR] [MY-010119] [Server] Aborting
2021-03-08T20:39:12.243212+08:00 0 [Warning] [MY-011068] [Server] The syntax 'validate password plugin' is deprecated and will be removed in a future release. Please use validate_password component instead.
2021-03-08T20:39:12.839299+08:00 0 [System] [MY-010910] [Server] /usr/local/mysql8/bin/mysqld: Shutdown complete (mysqld 8.0.23)  MySQL Community Server - GPL.

主要注意sql_mode、basedir、密码认证插件及字符集设置,其他参数最好还是按照原5.7的来,不需要做调整。

 最终调整后的参数文件如下:

###########
[client]
socket=/var/lib/mysql/mysql.sock
[mysqld]
server-id = 1
auto_increment_offset=3
auto_increment_increment=7
large_pages
log_timestamps=SYSTEM
innodb_numa_interleave=1
explicit_defaults_for_timestamp
transaction-isolation = READ-COMMITTED
log_bin_trust_function_creators = 1
datadir=/mysql/data
socket=/var/lib/mysql/mysql.sock
log-error=/mysql/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
log-bin=/mysql/bin_log/mysql-binlog
slow_query_log_file=/mysql/log/slow.log
general_log_file=/mysql/log/general.log
slow_query_log=1
log_slow_admin_statements=1
long_query_time=2
expire_logs_days=7
performance_schema = ON
character-set-server=utf8
collation-server=utf8_bin
skip-name-resolve
lower_case_table_names
skip-external-locking
key_buffer_size = 128M
max_allowed_packet = 16M
table_open_cache = 1024
table_open_cache_instances=4
sort_buffer_size = 8M
net_buffer_length = 8K
myisam_sort_buffer_size = 8M
max_connections = 2048
max_user_connections = 2000
#query_cache_size = 0
#query_cache_type = 0
tmp_table_size = 1024M
tmpdir=/mysql/tmp
max_heap_table_size = 1024M
innodb_log_files_in_group = 4
innodb_log_file_size = 1024M
innodb_undo_directory=/mysql/undo_tbls
innodb_undo_tablespaces=4
innodb_undo_log_truncate=on
innodb_flush_method= O_DIRECT
innodb_buffer_pool_size = 1G
innodb_buffer_pool_instances = 1
innodb_buffer_pool_chunk_size=128MB
innodb_log_buffer_size = 64M
innodb_file_per_table
innodb_data_file_path=ibdata1:1000M:autoextend
innodb_flush_log_at_trx_commit = 2
sync_binlog = 1
binlog-group-commit-sync-delay=10
binlog_group_commit_sync_no_delay_count=5
innodb_lock_wait_timeout = 50
innodb_rollback_on_timeout = ON
innodb_io_capacity = 2000
innodb_read_io_threads = 2
innodb_write_io_threads  = 2
innodb_thread_concurrency = 0
innodb_sync_spin_loops = 200
innodb_spin_wait_delay = 6
innodb_status_file = 1
innodb_doublewrite=1
innodb_max_dirty_pages_pct = 75
#innodb_support_xa=1
innodb_checksum_algorithm=crc32
innodb_adaptive_hash_index = 1
innodb_purge_threads=4
innodb_use_native_aio = 1
innodb_autoinc_lock_mode = 2
innodb_change_buffering = all
symbolic-links=0
binlog_format=ROW
default_storage_engine=InnoDB
lower_case_table_names=1
max_connections=3500


#for8.0
sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
character-set-server = utf8
collation_server = utf8_general_ci
basedir = /usr/local/mysql8
skip_ssl
default_authentication_plugin = mysql_native_password

其实就注释掉了上面说的3个8.0不支持的,新增了最后6个8.0需要的。

7、停现有mysql5.7.22

mysql -uroot -p


mysql> select version();
+------------+
| version()  |
+------------+
| 5.7.22-log |
+------------+
1 row in set (0.00 sec)

mysql> show variables like 'innodb_fast_shutdown';
+----------------------+-------+
| Variable_name        | Value |
+----------------------+-------+
| innodb_fast_shutdown | 1     |
+----------------------+-------+
1 row in set (0.01 sec)

# 确保数据都刷到硬盘上,更改成0

mysql> set global innodb_fast_shutdown=0;
Query OK, 0 rows affected (0.00 sec)

mysql> shutdown
    -> ;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye
[root@ho_test43 ~]# ps -ef| grep mysql
root      2935 17416  0 16:58 pts/1    00:00:00 grep --color=auto mysql
[root@ho_test43 ~]# 

8、启动 mysql8.0

[root@ho_test43 ~]# /usr/local/mysql8/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql &
[1] 4200
[root@ho_test43 ~]# 2021-03-08T08:59:33.968452Z mysqld_safe Logging to '/mysql/log/mysqld.log'.
2021-03-08T08:59:33.990673Z mysqld_safe Starting mysqld daemon with databases from /mysql/data

 9、检查日志

查看启动日志,看是否有报错

[root@ho_test43 ~]# tailf -n 100 /mysql/log/mysqld.log

最后如果启动成功,能看到如下的日志:

2021-03-08T20:40:17.808046+08:00 0 [Warning] [MY-013129] [Server] A message intended for a client cannot be sent there as no client-session is attached. Therefore, we're sending the information to the error-log instead: MY-001287 - 'validate password plugin' is deprecated and will be removed in a future release. Please use validate_password component instead
2021-03-08T20:40:18.057859+08:00 0 [Warning] [MY-011302] [Server] Plugin mysqlx reported: 'Failed at SSL configuration: "SSL context is not usable without certificate and private key"'
2021-03-08T20:40:18.058148+08:00 0 [System] [MY-010931] [Server] /usr/local/mysql8/bin/mysqld: ready for connections. Version: '8.0.23'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server - GPL.

 

10、检查mysql进程

root@ho_test43[/root]#ps -ef| grep mysql
root     27291 21894  0 10:34 pts/1    00:00:00 grep --color=auto mysql
root     27873     1  0 Mar08 ?        00:00:00 /bin/sh /usr/local/mysql8/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --pid-file=/var/run/mysqld/mysqld.pid
mysql    29049 27873  5 Mar08 ?        00:42:43 /usr/local/mysql8/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql8 --datadir=/mysql/data --plugin-dir=/usr/local/mysql8/lib/plugin --user=mysql --log-error=/mysql/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
root@ho_test43[/root]#

 

11、测试连接

root@ho_test43[/root]#/usr/local/mysql8/bin/mysql -uroot -p
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 60
Server version: 8.0.23 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases ;
+--------------------+
| Database           |
+--------------------+
| flow               |
| information_schema |
| mysql              |
| oss_design         |
| oss_edn            |
| oss_foa            |
| oss_im             |
| oss_isap           |
| oss_od             |
| oss_om             |
| oss_opb            |
| oss_si             |
| oss_wfm            |
| performance_schema |
| sys                |
+--------------------+
15 rows in set (0.01 sec)

mysql> quit
Bye

12、配置环境变量

修改/etc/profile的PATH变量,新增/usr/local/mysql8/bin

vi /etc/profile
export PATH=/usr/local/mysql8/bin:$PATH 

使环境变量生效

source /etc/profile

13、测试环境变量生效

root@ho_test43[/root]#which mysql
/usr/local/mysql8/bin/mysql
root@ho_test43[/root]#mysql -V
mysql  Ver 8.0.23 for Linux on x86_64 (MySQL Community Server - GPL)
root@ho_test43[/root]#
root@ho_test43[/root]#mysql -uroot -p
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 357
Server version: 8.0.23 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> quit
Bye
root@ho_test43[/root]#

至此,mysql5.7升级到mysql8.0已经完成。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是 Windows 平台 MySQL 5.7.22 免安装版本的安装步骤: 1. 下载 MySQL 5.7.22 免安装版本压缩包,可以在 MySQL 官网或者其他可信的下载站点上下载。 2. 解压缩下载的压缩包到一个目录下,例如:C:\mysql-5.7.22-winx64。 3. 在 MySQL 安装目录下创建一个 my.ini 配置文件。可以复制一份 my-default.ini,然后重命名为 my.ini。 4. 编辑 my.ini 配置文件,设置 MySQL 的基本配置信息,例如: ``` [mysql] default-character-set=utf8 [mysqld] port=3306 basedir=C:/mysql-5.7.22-winx64 datadir=C:/mysql-5.7.22-winx64/data default-storage-engine=INNODB character-set-server=utf8 collation-server=utf8_general_ci ``` 5. 打开命令行窗口,切换到 MySQL 安装目录的 bin 目录下。 6. 执行命令:mysqld --initialize --console,初始化 MySQL 数据库。 7. 执行命令:mysqld --install,安装 MySQL 服务。 8. 执行命令:net start mysql,启动 MySQL 服务。 9. 执行命令:mysql -u root -p,登录 MySQL 数据库。 10. 输入初始密码,成功登录后,就可以开始使用 MySQL 数据库了。 注意事项: 1. 如果需要修改 MySQL 的配置信息,可以在 my.ini 配置文件中进行修改,然后重启 MySQL 服务。 2. 如果 MySQL 服务启动失败,可以查看 MySQL 安装目录下的 error.log 文件,查看错误信息。 3. 在使用 MySQL 之前,需要先创建一个数据库和用户。可以使用 MySQL 命令行工具或者 MySQL 图形化工具来操作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值