需要有网
yum -y install jemalloc openssl-devel libaio wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz rpm -qa | grep mysql rpm -qa | grep mariadb rpm -e --nodeps mysql rpm -e --nodeps mariadb #如果上面筛选出包的话,在这里写包的名称删除即可 mkdir /home/fosafer tar -xf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz mv mysql-8.0.20-linux-glibc2.12-x86_64 /home/fosafer/mysql groupadd mysql useradd -r -g mysql -s /sbin/nologin mysql mkdir -p /home/fosafer/mysql/data mkdir -p /home/fosafer/mysql/logs mkdir -p /home/fosafer/mysql/conf mkdir -p /home/fosafer/mysql/status chown -R mysql:mysql /home/fosafer/mysql/data/ chown -R mysql:mysql /home/fosafer/mysql/logs/ chown -R mysql:mysql /home/fosafer/mysql/status/ chmod -R 755 /home/fosafer/mysql/status/ chmod -R 755 /home/fosafer/mysql/data/ chmod -R 755 /home/fosafer/mysql/logs/ #编写配置文件 cat << EOF > /home/fosafer/mysql/conf/my.cnf [mysqld] port=3306 basedir=/home/fosafer/mysql datadir=/home/fosafer/mysql/data log-error=/home/fosafer/mysql/logs/error.log socket=/home/fosafer/mysql/status/mysql.sock user=mysql default_authentication_plugin=mysql_native_password skip_host_cache skip-name-resolve=1 #skip-grant-tables [client] port=3306 socket=/home/fosafer/mysql/status/mysql.sock EOF #初始化数据库 /home/fosafer/mysql/bin/mysqld --defaults-file=/home/fosafer/mysql/conf/my.cnf --initialize --user=mysql #获取初始密码 tail -1 /home/fosafer/mysql/logs/error.log | awk '{print $13}' /home/fosafer/mysql/bin/mysqld_safe --defaults-file=/home/fosafer/mysql/conf/my.cnf & netstat -ntpl | grep mysqld #修改密码 /home/fosafer/mysql/bin/mysqladmin -uroot -p'V:cVV+>R7Kbg' -S /home/fosafer/mysql/status/mysql.sock password '123456' #测试是否修改成功 /home/fosafer/mysql/bin/mysql -uroot -p123456 -S /home/fosafer/mysql/status/mysql.sock -e "show databases"