1、查看并卸载系统自带的 Mariadb
rpm -qa|grep mariadb //查看 rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64 //卸载
2、下载并安装MySQL官方的 Yum(由于CentOS 的yum源中没有mysql,需要到mysql的官网下载yum repo配置文件),建议建一个专门的目录去操作
wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
3、下载mysql的yum源配置
wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
4、安装mysql的yum源
yum -y install mysql57-community-release-el7-11.noarch.rpm
5、 使用yum方式安装mysql
yum -y install mysql-server
6、安装过程中报错解决,如果没有提示错误可忽略
问题:
警告:/var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.41-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY mysql-community-common-5.7.41-1.el7.x86_64.rpm 的公钥尚未安装 mysql-community-libs-compat-5.7.41-1.el7.x86_64.rpm 的公钥尚未安装 失败的软件包是:mysql-community-libs-compat-5.7.41-1.el7.x86_64 GPG 密钥配置为:file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
运行命令:
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
然后重新安装:
yum -y install mysql-server
7、启动Mysql
service mysqld start
service mysqld status
service mysqld stop
8、获取临时密码
cat /var/log/mysqld.log | grep password
9、登录mysql
mysql -u root -p
使用临时密码登录
10、修改密码,密码太简单会报错
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Root@..123456';
11、开启远程连接
grant all privileges on *.* to 'root'@'%' identified by 'Root@..123456' with grant option;
flush privileges;
最后就可使用工具测试连接了。
修改mysql 数据目录的操作:
1、停止Mysql服务
service mysqld stop
2、创建新的数据目录并赋权
sudo mkdir -p /new_datadir sudo chown mysql:mysql /new_datadir sudo chmod 750 /new_datadir
3、复制数据文件
rsync -av /var/lib/mysql/ /new_datadir/
4、修改Mysql的配置文件
datadir=/new_datadir
5、关闭SELinux ,不然Mysql启动失败