一、Mysql数据库的安装与配置
-
卸载mariadb数据库
rpm -qa | grep mariadb rpm -e --nodeps mariadb文件名
-
下载mysql5.7.28软件包
wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar
-
解压安装
yum -y install numactl yum -y install libaio* #安装依赖包 tar -xvf mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar # 解压文件,解压出一系列rpm 文件 按照指定顺序安装rpm包,这几个文件是存在依赖关系的,所以在安装时有对应的优先级,需要按顺序安装: rpm -ivh mysql-community-common-5.7.28-1.el7.x86_64.rpm rpm -ivh mysql-community-libs-5.7.28-1.el7.x86_64.rpm rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm rpm -ivh mysql-community-devel-5.7.28-1.el7.x86_64.rpm
-
启动mysql服务
systemctl start mysqld
systemctl enable mysqld
netstat -lntp | grep 3306
-
修改 my.cnf 配置文件
编辑my.cnf:vim /etc/my.cnf
插入以下代码:
validate_password=off default-storage-engine=INNODB character-set-server=utf8 collation-server=utf8_general_ci
## validate_password=off
的意思是关闭密码验证插件(这一句必须加上,因为在修改密码的时候如果不加上会非常的麻烦)
重启 mysql 服务:systemctl restart mysqld
-
重置密码
mysql5.7初始化后,会产生一个临时登录密码,前面在 my.cnf 文件中配置的日志路径是log-error=/var/log/mysqld.log
, 查看此路径下面的mysqld.log
日志, 可以找到临时密码。
示例行:A temporary password is generated for root@localhost: I.9hRnQ(4isD
[root@localhost ~]# cat /var/log/mysqld.log | grep root@localhost
2020-04-11T06:56:57.048502Z 1 [Note] A temporary password is generated for root@localhost: I.9hRnQ(4isD
登录数据库重置密码:
[root@localhost ~]# mysql -u root -p Enter password: #输入数据库密码,建议钻贴 mysql> alter user ‘root‘@‘localhost‘ identified by ‘123456‘; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> exit
重启mysql服务
参考与:https://blog.csdn.net/shangyexin/article/details/102720834