说明:数据文件的默认存放位置为/var/lib/mysql/
1.查询是否有残留软件
[root@kht118 kht]# rpm -aq|grep mysql
[root@kht118 kht]# rpm -aq|grep mariadb
mariadb-libs-5.5.65-1.el7.x86_64
[root@kht118 kht]# yum remove -y mariadb-libs-5.5.65-1.el7.x86_64
[root@kht118 mysql]# find / -name *mysql*
[root@kht118 mysql]# find / -name *mariadb*
2.上传解压并安装
[root@kht118 kht]# tar xf MySQL-5.6.51-1.el7.x86_64.rpm-bundle.tar
[root@kht118 kht]# rpm -qa|grep libaio
libaio-devel-0.3.109-13.el7.x86_64
libaio-0.3.109-13.el7.x86_64
[root@kht118 kht]# yum install libaio-devel.x86_64 -y
[root@kht118 ~]# rpm -qa|grep perl-Data-Dumper
perl-Data-Dumper-2.145-3.el7.x86_64
[root@kht118 kht]# yum install -y perl-Data-Dumper
[root@kht118 kht]# rpm -ivh MySQL-client-5.6.51-1.el7.x86_64.rpm
[root@kht118 kht]# rpm -ivh MySQL-server-5.6.51-1.el7.x86_64.rpm
[root@kht118 kht]# systemctl status mysql
[root@kht118 kht]# systemctl start mysql
#设置mysql开机启动
[root@kht118 ~]# systemctl enable mysql
mysql.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig mysql on
[root@kht118 ~]# chkconfig mysql on
[root@kht118 ~]# chkconfig --list
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
#查找临时密码
[root@kht118 kht]# cat /root/.mysql_secret
# Therandom password set for the root user at Mon Nov 21 10:13:01 2022 (local time): Eq29YJBjmLoDV2Bq
#登录mysql
[root@kht118 kht]# mysql -uroot -p
#设置新密码
mysql> set password = password('KHTkht123456!');
mysql> use mysql;
mysql> select user,host from user;
+------+-----------+
| user | host |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1 |
| root | kht118 |
| root | localhost |
+------+-----------+
mysql> grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
mysql> flush privileges;
mysql> select user,host from user;
+------+-----------+
| user | host |
+------+-----------+
| root | % |
| root | 127.0.0.1 |
| root | ::1 |
| root | kht118 |
| root | localhost |
+------+-----------+
#查看时区
mysql> show VARIABLES like '%time_zone%';
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| system_time_zone | CST |
| time_zone | SYSTEM |
+------------------+--------+
#查看当前时间
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2022-11-21 10:45:17 |
+---------------------+