关于Linux下MySQL密码得相关问题
第一种安装方式(初始化的磁盘,会先下载mariadb)
首先进行yum安装MySQL
yum install mysql 这样是行不通的,以目前mysql5.7来说,是下载不下来的
/*然后执行一个 mysql -v
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
这个时候回报一个mysql-server错误*/
yum install mysql-server
/*这个时候有可能会报两个错误
一、依赖错误*/
# Error downloading packages:
# mysql-community-client-5.7.26-1.el6.x86_64: [Errno 256] No more mirrors to try.
# mysql-community-common-5.7.26-1.el6.x86_64: [Errno 256] No more mirrors to try.
# mysql-community-libs-5.7.26-1.el6.x86_64: [Errno 256] No more mirrors to try.
** 解决思路
** 接下来,我们需要去清楚缓存
yum clean cache
yum makecache
** 清楚完毕之后,再去执行
yum install mysql-server
** 这个时候应该就差不多可以了
/*二、mysql-server错误
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
No package mysql-server available.
Error: Nothing to do
出现这个错误说明是,你的yum包里面没有mysql-server这个rpm包
*/
** 解决思路
** 下载rpm包
rpm -ivh https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm
** 然后进行yum
yum install mysql-server
第二种安装方式 (推荐2023-09-16修改,安装mysql8.0版本)
下载并安装MySQL官方的 Yum Repository
** 首先更新mysql5.7的yum源
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm
** 执行yum安装mysql
yum -y install mysql-community-server
** 不出意外的话,会出现报错:Error: Unable to find a match: mysql-community-server
** 出现报错执行(效果:关闭mysql模块)
yum module disable mysql
yum -y install mysql-community-server
** 这里不出意外 依旧会有一个报错:Error: GPG check FAILED 这个是因为5.7没有el8的包。所以我们需要安装mysql8.0
** 执行跳过gpg验证,下载mysql
yum -y install mysql-community-server --nogpgcheck
** 接下来执行,有依赖会自行下载,时间可能会久一点,如果之前执行过yum install mysql
** 执行下面的操作会把之前的mariadb覆盖
yum -y install mysql-community-server
** 执行到这里,可能会出现一个报错:The GPG keys listed for the "MySQL 5.7 Community Server"
repository are already installed but they are not correct for this package.
** 执行,更行GPG key 命令
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
最后:yum -y install mysql-community-server --nogpgcheck
mysql -V或者mysql --version查看是否安装成功
关于mysql8.0初始化后的密码修改
第一种:
查看mysql初始化的默认密码
cat /var/log/mysqld.log
第二种
** 查询my.cnf文件
find / -name my.cnf
** 修改my.cnf文件
vi /etc/my.cnf
** 新增命令。功能:跳过密码验证,进入数据库
[mysqld]
skip-grant-tables
** 进入数据库修改密码
mysql -u root -p
** 需要密码直接回车进入数据库
** 因为我们绕过密码验证,如果执行mysql8.0的修改密码方法:
ALTER USER 'root'@'localhost' IDENTIFIED BY '你的密码';
** 报错:ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables
option so it cannot execute this statement
** 需要优先执行:
flush privileges;
** 接下来执行:ALTER USER 'root'@'localhost' IDENTIFIED BY '你的密码';
** 报错:Your password does not satisfy the current policy requirements
这里是因为你设置的密码过于简单,mysql8.0内置了验证,建议:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'ABSabs@-123'; (大小写英文、特殊符号@.-+、数字)