centos7完全卸载和安装mysql8

问题描述

最近安装了MYSQL8,遇到了各种问题,总体汇总一下,凡是无法启动就是my.cnf和初始化的参数不匹配。

第一种

启动前设置了mysqld --initialize --user=mysql --lower-case-table-names=1,my.cnf文件却没有修改就去启动。

第二种

启动没有设置mysqld --initialize,可以启动成功,但是又停止了服务,然后修改了my.cnf文件,在文件中增加了lower-case-table-names=1。

第三种

安装了不匹配的版本,导致yum install mysql-server安装失败。

错误日志1

[root@iZuf6it0abhodk626wob0vZ ~]# sudo service mysqld start
Redirecting to /bin/systemctl start mysqld.service
Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
[root@iZuf6it0abhodk626wob0vZ ~]# journalctl -xe
10月 31 08:34:02 iZuf6it0abhodk626wob0vZ systemd[1]: Starting MySQL Server...
-- Subject: Unit mysqld.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit mysqld.service has begun starting up.
10月 31 08:34:03 iZuf6it0abhodk626wob0vZ systemd[1]: mysqld.service: main process exited, code=exited, status=1/FAILURE
10月 31 08:34:03 iZuf6it0abhodk626wob0vZ systemd[1]: Failed to start MySQL Server.
-- Subject: Unit mysqld.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit mysqld.service has failed.
-- 
-- The result is failed.
10月 31 08:34:03 iZuf6it0abhodk626wob0vZ systemd[1]: Unit mysqld.service entered failed state.
10月 31 08:34:03 iZuf6it0abhodk626wob0vZ systemd[1]: mysqld.service failed.
10月 31 08:34:03 iZuf6it0abhodk626wob0vZ polkitd[567]: Unregistered Authentication Agent for unix-process:23264:394775943 (system bus name :1.15617, objec

错误日志2

[root@iZuf6it0abhodk626wob0vZ ~]# sudo service mysqld start
Redirecting to /bin/systemctl start mysqld.service
Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
[root@iZuf6it0abhodk626wob0vZ ~]# journalctl -xe
-- Unit mysqld.service has begun starting up.
10月 31 08:32:20 iZuf6it0abhodk626wob0vZ systemd[1]: mysqld.service: main process exited, code=exited, status=1/FAILURE
10月 31 08:32:20 iZuf6it0abhodk626wob0vZ systemd[1]: Failed to start MySQL Server.
-- Subject: Unit mysqld.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit mysqld.service has failed.
-- 
-- The result is failed.
10月 31 08:32:20 iZuf6it0abhodk626wob0vZ systemd[1]: Unit mysqld.service entered failed state.
10月 31 08:32:20 iZuf6it0abhodk626wob0vZ systemd[1]: mysqld.service failed.
10月 31 08:32:20 iZuf6it0abhodk626wob0vZ polkitd[567]: Unregistered Authentication Agent for unix-process:21164:394765598 (system bus name :1.15615, objec
10月 31 08:32:20 iZuf6it0abhodk626wob0vZ sshd[21248]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=120.55.40.20
10月 31 08:32:20 iZuf6it0abhodk626wob0vZ sshd[21248]: pam_succeed_if(sshd:auth): requirement "uid >= 1000" not met by user "root"
10月 31 08:32:22 iZuf6it0abhodk626wob0vZ sshd[21248]: Failed password for root from 120.55.40.20 port 50908 ssh2
10月 31 08:32:22 iZuf6it0abhodk626wob0vZ sshd[21248]: Received disconnect from 120.55.40.20 port 50908:11: Bye Bye [preauth]
10月 31 08:32:22 iZuf6it0abhodk626wob0vZ sshd[21248]: Disconnected from 120.55.40.20 port 50908 [preauth]

卸载教程

# ------ 卸载mysql
rpm -qa | grep mariadb
rpm -e --nodeps mariadb-libs
mysqladmin -V
# 查看已安装的mysql安装包,参照下面的截图
rpm -qa|grep mysql
 
# 使用如下指令将搜索到的mysql安装包全部卸载
rpm -e --nodeps mysql-community-client-plugins-8.0.35-1.el7.x86_64
rpm -e --nodeps mysql-community-client-plugins-8.0.35-1.el7.x86_64
rpm -e --nodeps mysql-community-server-8.0.35-1.el7.x86_64
rpm -e --nodeps mysql-community-common-8.0.35-1.el7.x86_64
rpm -e --nodeps mysql-community-libs-8.0.35-1.el7.x86_64
rpm -e --nodeps mysql-community-icu-data-files-8.0.35-1.el7.x86_64
rpm -e --nodeps mysql80-community-release-el7-1.noarch
rpm -e --nodeps mysql-community-client-8.0.35-1.el7.x86_64

# 删除配置文件
rm -vf /etc/my.cnf.rpmsave
# 删除日志文件
rm -vf /var/log/mysqld.log
# 查看并删除其他残留文件
find /  -name  mysql
# 依次删除
rm -rf 对应路径
# ------ 卸载mysql

安装教程


# ------ 安装mysql


#移除yum缓存
yum clean packages

# 如果失败不需要关注,继续向下
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

sudo yum install https://repo.mysql.com/mysql80-community-release-el7-1.noarch.rpm
sudo yum install mysql-server

# 查看安装的版本
mysqladmin --version
# 初始化mysql:使用mysql系统用户以安全模式为mysql的root用户生成临时密码,第一次登录后要立马修改。
# 这里一定要注意
# 0 --大小写敏感。(Unix,Linux默认) 
# 1 --大小写不敏感。(Windows默认) 创建的库表时
# 2 --大小写不敏感(OS X默认) 创建的库表将原样保存在磁盘上
mysqld --initialize --user=mysql --lower-case-table-names=1 
# 然后修改/etc/my.cnf文件中增加lower-case-table-names=1,否则mysql无法启动
# 然后在启动mysql

# 查看临时密码  
cat /var/log/mysqld.log
# 解锁root账户,避免requirement "uid >= 1000" not met by user "root"
passwd -u root

sudo service mysqld start
service mysqld status

# 默认没有密码
mysql -uroot -p
# 直接回车,然后输入刚才查看的密码 +E-nlpd,k7iX

ALTER USER 'root'@'localhost' IDENTIFIED BY 'Pass@word123';
# 修改Host为通配符%
update mysql.user set host = '%' where user ='root';

# 创建用户,可以忽略
create user zhangsan@'%' identified by 'Pass@word123';
# 赋权,可以忽略
GRANT ALL PRIVILEGES ON *.* TO zhangsan;

# 刷新权限
flush privileges;
# 退出
exit;
# 停止服务
sudo service mysqld stop

my.cnf

# 在etc下新建或修改my.cnf文件,如果my.cnf已经存在不要删除,也不要修改已经有的配置,添加自己的配置在下面即可。
vim /etc/my.cnf
[client]
port=3308

[mysql]
no-beep

[mysqld]
port=3308

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
skip_ssl
server-id=1
character-set-server=utf8mb4
lower_case_table_names=1

autocommit=1
authentication_policy=mysql_native_password,,
default-storage-engine=INNODB
sql-mode="ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"
long_query_time=10
max_connections=151
table_open_cache=4000
temptable_max_ram=1G
tmp_table_size=95M
internal_tmp_mem_storage_engine=TempTable
myisam_max_sort_file_size=2146435072
myisam_sort_buffer_size=181M
key_buffer_size=8M
read_buffer_size=128K
read_rnd_buffer_size=256K
innodb_flush_log_at_trx_commit=1
innodb_log_buffer_size=16M
innodb_buffer_pool_size=128M
innodb_redo_log_capacity=100M
innodb_thread_concurrency=17
innodb_autoextend_increment=64
innodb_buffer_pool_instances=8
innodb_concurrency_tickets=5000
innodb_old_blocks_time=1000
innodb_stats_on_metadata=0
innodb_file_per_table=1
innodb_checksum_algorithm=0
flush_time=0
join_buffer_size=256K
max_allowed_packet=64M
max_connect_errors=100
open_files_limit=8161
sort_buffer_size=256K
binlog_row_event_max_size=8K
sync_source_info=10000
sync_relay_log=10000
sync_relay_log_info=10000


# 注释掉disable_ssl
# disable_ssl

你可能感兴趣的:(JAVA,mysql8,centos7,linux,mysql卸载,mysql安装)