检查是否自带MySQL
查看mysql服务
bash
rpm -qa | grep mysql
卸载MySQL
bash
# 普通卸载
rpm -e mysql
# 强力卸载,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力卸载
rpm -e --nodeps mysql
检查是否存在MariaDB
查看MariaDB
bash
rpm -qa | grep mariadb
卸载MariaDB
bash
# 普通卸载
rpm -e xxx
# 强力卸载,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力卸载
rpm -e --nodeps xxx
Yum方式安装MySQL
下载地址:https://dev.mysql.com/downloads/repo/yum/,按照centos版本选择下载
禁用自带Yum源
bash
yum module disable mysql
下载Yum源配置
bash
wget https://dev.mysql.com/get/mysql80-community-release-el7-11.noarch.rpm
安装Yum源
bash
yum -y install mysql80-community-release-el7-11.noarch.rpm
安装MySQL
bash
yum -y install mysql-server
配置端口和大小写敏感
bash
# 编辑MySQL配置文件
vim /etc/my.cnf
# 在文件中写入以下内容
port=3306
lower_case_table_names=1
启动/配置MySQL
启动SQL
bash
systemctl start mysqld.service
获取初始密码
bash
grep "password" /var/log/mysqld.log
效果,拿到mB=-k!3SsgNF
,这就是mysql临时登录密码
bash
[root@test mysql]# grep "password" /var/log/mysqld.log
2024-03-06T08:05:48.745784Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: mB=-k!3SsgNF
登录MySQL
bash
mysql -uroot -p
配置MySQL
bash
# 修改密码
alter user user() identified by 'Mysql123$%^';
# 修改远程登录权限
use mysql;
update user set `host` = '%' where `user` = 'root';
# 刷新配置
flush privileges;
常用操作命令
bash
# 开机自启
systemctl enable mysqld.service
# 取消开机自启
systemctl disable mysqld.service
# 启动服务
systemctl start mysqld.service
# 关闭服务
systemctl stop mysqld.service
# 关闭服务
systemctl restart mysqld.service
# 查看服务状态
systemctl status mysqld.service