1、删除CentOS 7.7内置的MariaDB相关组件:
# rpm -qa | grep -i mariadb --> mariadb-libs-5.5.64-1.el7.x86_64
# rpm -e --nodeps mariadb-libs-5.5.64-1.el7.x86_64
如果之前安装过MySQL,先卸载:
下面是卸载步骤:
(1)、查看是否安装了mysql
rpm -qa | grep -i mysql // 查看命令1
yum list install mysql* // 查看命令2
这个就可以查看到当前安装的mysql的信息
(2)、卸载mysql安装包
yum remove mysql mysql-server mysql-libs compat-mysql51
yum remove mysql-community-release
rpm -e --nodeps mysql-community-libs-5.7.22-1.el7.x86_64
rpm -e –nodeps mysql57-community-release-el7-11.noarch
mysql-community-libs-5.7.28-1.el7.x86_64
mysql57-community-release-el7-11.noarch
mysql-community-client-5.7.28-1.el7.x86_64
mysql-community-test-5.7.28-1.el7.x86_64
mysql-community-server-5.7.28-1.el7.x86_64
mysql-community-devel-5.7.28-1.el7.x86_64
mysql-community-common-5.7.28-1.el7.x86_64
mysql-community-libs-compat-5.7.28-1.el7.x86_64
总之删到通过上面两种命令查不出来任何有关mysql的东西。
(3)、删除残留的mysql目录或文件:
查询mysql安装目录
whereis mysql
(4)、find / -name mysql
删除查询出的目录,我的这个是在没有删除安装包的情况下截的图,所以可能比较多。
rm -rf /usr/lib64/mysql
rm -rf /usr/share/mysql
rm -rf /usr/bin/mysql
rm -rf /etc/logrotate.d/mysql
rm -rf /var/lib/mysql
rm -rf /var/lib/mysql/mysql
总之删到通过上面两种命令查不出来任何有关mysql的东西。
(5)、继续删除
删除mysql 配置文件
rm –rf /usr/my.cnf
rm -rf /root/.mysql_sercret
(6)、删除mysql开机自启动服务
chkconfig --list | grep -i mysql
chkconfig --del mysqld // 服务名为你设置时候自己设置的名字
如果存在/etc/my.cnf配置文件,先删除:# rm -rf /etc/my.cnf
安装MySQL:
2、安装mysql57-community-release-el7.rpm:
# rpm -ivh http://repo.mysql.com/mysql57-community-release-el7.rpm
备注:安装后会在/etc/yum.repos.d目录中生成mysql-community-source.repo和mysql-community.repo
3、安装MySQL:
# yum list all | grep mysql-community
# yum -y install mysql-community-client mysql-community-common mysql-community-devel mysql-community-libs mysql-community-libs-compat mysql-community-server mysql-community-test
4、初始化MySQL:# mysqld --initialize --user=mysql --datadir=/var/lib/mysql
备注:初始化之前确保/var/lib/mysql目录为空
5、修改/etc/my.cnf配置文件:
# mv /etc/my.cnf /etc/my.cnf.bak
# vim /etc/my.cnf
[mysqld]
port=3306
socket=/var/lib/mysql/mysql.sock
datadir=/var/lib/mysql
pid-file=/var/run/mysqld/mysqld.pid
log-error=/var/log/mysqld.log
lower_case_table_names=1
character_set_server=utf8mb4
collation_server=utf8mb4_general_ci
innodb_file_per_table=1
skip_name_resolve=1
slow_query_log=1
slow_query_log_file=mysql-slow.log
symbolic-links=0
explicit_defaults_for_timestamp=1
server_id=1
sync_binlog=1
innodb_flush_log_at_trx_commit=1
log_bin=mysql-bin
log_bin_index=mysql-bin.index
binlog_format=row
6、启动MySQL服务:
# systemctl start mysqld.service
# systemctl status mysqld.service
# ps aux | grep mysqld
# ss -tunlp | grep 3306
# tail -100 /var/log/mysqld.log
7、配置MySQL服务开机自启:# systemctl enable mysqld.service
8、查看root@localhost用户的初始密码:# grep password /var/log/mysqld.log
9、配置MySQL安全向导:# mysql_secure_installation
10、授权root用户远程登录:
# mysql -uroot -p
mysql> create user root@'%' identified by '123456';//这里的%是所有的ip地址,可以换成特定的地址就可以控制ip访问了,下面的同样的。
mysql> grant all privileges on *.* to root@'%';
mysql> flush privileges;
11、使用Navicat Premium连接MySQL: