有学有练才叫学习:学而不思则罔,思而不学则殆:学而不习,纸上谈兵,习而不进,画地为牢!

卸载mysql8 CentOS7(并重新安装MySQL8)

MySQL 炮渣日记 4周前 (11-13) 18次浏览 已收录 0个评论 扫描二维码

卸载 MySQL5或者MySQL8

#1. 停止MySQL服务
systemctl stop mysqld
 
#2. 查询MySQL的安装文件
rpm -qa | grep -i mysql
 
#3. 卸载上述查询出来的所有的MySQL安装包
# mysql-x.x.x.x  是第二步查出来的内容,从下往上一个一个进行处理。
rpm -e --nodeps mysql-x.x.x.x
 
#4. 删除MySQL的数据存放目录
rm -rf /var/lib/mysql/
 
#5. 删除MySQL的配置文件备份
rm -rf /etc/my.cnf.rpmsave

安装 MySQL8

cd /home/
mkdir mysql8
cd mysql8
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.30-1.el7.x86_64.rpm-bundle.tar
tar -xvf mysql-8.0.30-1.el7.x86_64.rpm-bundle.tar

yum -y install glibc
yum -y install glibc-static libstdc++-static
yum -y install libaio

yum -y remove mysql-libs

chattr -i /etc/passwd;chattr -i /etc/shadow;chattr -i /etc/group;chattr -i /etc/sudoers

groupadd mysql
useradd mysql -g mysql -M -s /sbin/nologin

rpm -ivh mysql-community-common-8.0.30-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-plugins-8.0.30-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.30-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-8.0.30-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.30-1.el7.x86_64.rpm
rpm -ivh mysql-community-icu-data-files-8.0.30-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.30-1.el7.x86_64.rpm


cp -r /var/lib/mysql /home/data/
chown mysql:mysql -R /home/data/mysql /home/logs/mysql/

cat>/etc/my.cnf<<EOF
[mysqld]
datadir=/home/data/mysql/data
socket=/home/data/mysql/mysql.sock
log-error=/home/data/mysql/mysqld.log
pid-file=//home/data/mysql/mysqld.pid

explicit_defaults_for_timestamp=true

character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
lower_case_table_names = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLE
#plugin-load=validate_password.so 
#validate-password=OFF

log-bin = /home/logs/mysql/mysql-bin.log
expire-logs-days = 14
server-id = 1

join_buffer_size = 128M
tmp_table_size = 128M
sort_buffer_size = 128M
read_buffer_size = 256M
read_rnd_buffer_size = 128M
#innodb_log_file_size = 2G
innodb_log_buffer_size = 8M
innodb_buffer_pool_size = 500M
max_connections=1000

wait_timeout=31536000
interactive_timeout=31536000

[mysql]
socket=/home/data/mysql/mysql.sock

[client]
socket=/home/data/mysql/mysql.sock

[mysqldump]
socket=/home/data/mysql/mysql.sock

[mysqladmin]
socket=/home/data/mysql/mysql.sock

EOF

cd /home/data/mysql/
# 这里需要注意,要创建一个mysql的log文件,并且给mysql用户权限。
vi mysqld.log
chown -Rf mysql.mysql mysqld.log
chmod 755 mysqld.log

mysqld --initialize --user=mysql

systemctl start mysqld
systemctl status mysqld
systemctl enable mysqld

cat mysqld.log | grep password
mysql -u root -p

use mysql;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY "Aa123456";
flush privileges;

以上脚本代码,复制粘贴执行就行,在mysql8.0.31上测试有点问题,还没有调整。在mysql8.0.30版本测试通过。

喜欢 (0)
炮渣日记
关于作者:
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址