Centos 7 安装MySQ5.7
卸载Centos7自带的mariadb ,文件有冲突
[root@localhost ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[root@localhost ~]# rpm -e mariadb-libs-5.5.56-2.el7.x86_64 --nodeps
[root@localhost ~]# rpm -qa|grep mariadb
## 无
安装mysql
#### 安装包目录
[root@localhost ~]# mkdir /soft/software/mysql
##### 安装包上传到这个文件夹下面 在解压
[root@localhost ~]# tar -xvf mysql-5.7.29-1.el7.x86_64.rpm-bundle.tar
# libaio 安装 不然mysql 会报错 可以提前安装好
[root@localhost ~]# yum -y install libaio
[root@localhost ~]# rpm -ivh mysql-community-common-5.7.29-1.el7.x86_64.rpm mysql-community-libs-5.7.29-1.el7.x86_64.rpm mysql-community-client-5.7.29-1.el7.x86_64.rpm mysql-community-server-5.7.29-1.el7.x86_64.rpm
mysql初始化
#初始化
[root@localhost ~]# mysqld --initialize
#更改所属组
[root@localhost ~]# chown mysql:mysql -R 777 /var/lib/mysql
#启动mysql
[root@localhost ~]# systemctl start mysqld.service
#查看生成的临时root密码
[root@localhost ~]# cat /var/log/mysqld.log
[root@localhost mysql]# cat /var/log/mysqld.log
2022-07-12T13:03:57.618823Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-07-12T13:03:57.827400Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-07-12T13:03:57.873049Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-07-12T13:03:57.943790Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 175b9eda-01e3-11ed-95d6-000c297fc018.
2022-07-12T13:03:57.944447Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-07-12T13:03:58.772215Z 0 [Warning] CA certificate ca.pem is self signed.
##### root@localhost: j_ol6k#o7!cE
2022-07-12T13:03:58.916200Z 1 [Note] A temporary password is generated for root@localhost: j_ol6k#o7!cE
2022-07-12T13:04:12.673943Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-07-12T13:04:12.675334Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.29) starting as process 2078 ...
2022-07-12T13:04:12.678237Z 0 [Note] InnoDB: PUNCH HOLE support available
2022-07-12T13:04:12.678260Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2022-07-12T13:04:12.678264Z 0 [Note] InnoDB: Uses event mutexes
2022-07-12T13:04:12.678267Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2022-07-12T13:04:12.678269Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2022-07-12T13:04:12.678272Z 0 [Note] InnoDB: Using Linux native AIO
修改root密码 授权远程访问
[root@localhost ~]# mysql -u root -p
Enter password: #时密码
# 用户名root 密码也是root
mysql> alter user user() identified by "root";
Query OK, 0 rows affected (0.00 sec)
#授权
mysql> use mysql;
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
###立刻刷新
mysql> FLUSH PRIVILEGES;
###退出客户单连接
mysql> exit;
服务启停脚本
#mysql 关闭
systemctl stop mysqld
#mysql 状态查看
systemctl status mysqld
#mysql 开启服务
systemctl start mysqld
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!建议自启动
[root@localhost ~]# systemctl enable mysqld
Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /usr/lib/systemd/system/mysqld.service.
卸载mysql 5.7
#关闭mysql服务
systemctl stop mysqld.service
#查找安装mysql的rpm包
[root@localhost ~]# rpm -qa | grep -i mysql
mysql-community-libs-5.7.29-1.el7.x86_64
mysql-community-common-5.7.29-1.el7.x86_64
mysql-community-client-5.7.29-1.el7.x86_64
mysql-community-server-5.7.29-1.el7.x86_64
#卸载
[root@localhost ~]# yum remove mysql-community-libs-5.7.29-1.el7.x86_64 mysql-community-common-5.7.29-1.el7.x86_64 mysql-community-client-5.7.29-1.el7.x86_64 mysql-community-server-5.7.29-1.el7.x86_64
#mysql相关目录 删除
[root@localhost ~]# find / -name mysql
/var/lib/mysql
/var/lib/mysql/mysql
/usr/share/mysql
[root@localhost ~]# rm -rf /var/lib/mysql
[root@localhost ~]# rm -rf /var/lib/mysql/mysql
[root@localhost ~]# rm -rf /usr/share/mysql
#删除日志和配置文件
rm -rf /etc/my.cnf
rm -rf /var/log/mysqld.log
远程连接还需要放开端口,或者关闭防火墙
##### 关闭防火墙
[root@localhost mysql]# systemctl stop firewalld
##### 禁止开启启动防火墙
[root@localhost mysql]# systemctl disable firewalld