centos7.6 安装 mysql5.7

安装netstat工具

yum install net-tools

查看程序例如:是Java还是redis

netstat -tunlp|grep 8080

查看进程号:ps -ef | grep java

 查看java程序的执行安装路径:

[root@VM-16-9-centos ~]# ls -l /proc/27580/cwd
lrwxrwxrwx 1 root root 0 May 3 06:18 /proc/27580/cwd -> /usr/apache-tomcat-8.5.82/bin

卸载mariadb

rpm -qa | grep mariadb

rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64 //名称会有变

CentOS 7.6 内部集成了mariadb,而安装mysql的话会和mariadb的文件冲突,所以需要先卸载掉mariadb。

步骤一:更新YUM源

运行以下命令添加epel源。 yum install  https://repo.ius.io/ius-release-el7.rpm  https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

步骤二:安装MySQL

运行以下命令更新YUM源。 rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm

查看各版本启动状况

yum repolist all | grep mysql

 

 

 禁用8.0,开启5.7

您需要先运行命令yum module disable mysql禁用默认的MySQL模块,再安装MySQL。

yum-config-manager --disable mysql80-community

yum-config-manager --enable mysql57-community

命令在yum-utils 包里,安装既可以解决无法找到yum-config-manager命令:

yum -y install yum-utils

安装mysqll

yum -y install mysql-community-server

如果安装失败:

出现上述提示原因是 Mysql 的 GPG 升级了,需要重新获取

rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

重新安装 Mysql 正常

运行以下命令查看MySQL版本号。

mysql -V

返回结果如下所示,表示MySQL安装成功。

mysql Ver 14.14 Distrib 5.7.36, for Linux (x86_64) using EditLine wrapper

运行以下命令启动Mysql

systemctl start mysqld

依次运行以下命令设置开机启动Mysql

systemctl enable mysqld systemctl daemon-reload

查看默认生成密码

grep 'temporary password' /var/log/mysqld.log

运行以下命令配置MySQL的安全性。

mysql_secure_installation

输入MySQL的初始密码。
说明 在输入密码时,系统为了最大限度的保证数据安全,命令行将不做任何回显。您只需要输入正确的密码信息,然后按Enter键即可。

为MySQL设置新密码。

The existing password for the user account root has expired. Please set a new password.  
New password: #输入新密码。长度为8至30个字符,必须同时包含大小写英文字母、数字和特殊符号。特殊符号包含()` ~!@#$%^&*-+=|{}[]:;‘<>,.?/  

Re-enter new password: #确认新密码。 
The 'validate_password' plugin is installed on the server. 
The subsequent steps will run with the existing configuration 
of the plugin. Using existing password for root. 
Estimated strength of the password: 100#返回结果包含您设置的密码强度。 
Change the password for root ? ((Press y|Y for Yes, any other key for No) :Y #您需要输入Y以确认使用新密码。#新密码设置完成后,需要再次验证新密码。 
New password:#再次输入新密码。  Re-enter new password:#再次确认新密码。 
Estimated strength of the password: 100 Do you wish to continuewith the password provided?(Press y|Y for Yes, any other key for No) :Y #您需要输入Y,再次确认使用新密码。

输入Y删除匿名用户。

Removeanonymoususers?(Pressy|YforYes,anyotherkeyforNo):Y
Success.

输入Y禁止使用root用户远程登录MySQL

Disallowrootloginremotely?(Pressy|YforYes,anyotherkeyforNo):Y
Success.
Disallowrootloginremotely?(Pressy|YforYes,anyotherkeyforNo):Y Success.

  

Remove test database and access to it? (Press y|Y for Yes, any other key for No) :Y  
- Dropping test database... Success.   
- Removing privileges on test database... Success.

输入Y重新加载授权表。

Reloadprivilegetablesnow?(Pressy|YforYes,anyotherkeyforNo):Y
Success.All done!

 

 

另一种修改root密码

登录修改密码

mysql -uroot -p

修改密码

ALTER USER 'root'@'localhost' IDENTIFIED BY 'NoPassword564925080!';

 

授权远程登录用户

GRANT ALL PRIVILEGES ON *.* TO 'noneplus'@'%' IDENTIFIED BY 'Noneplus564925080!' WITH GRANT OPTION; flush privileges;

posted on 2022-10-04 22:38  王飞侠  阅读(459)  评论(0编辑  收藏  举报

导航