linux系统上安装mysql数据库教程

centos7中安装mysql详细步骤

CentOS7安装MySQL详细教程

1、 下载并安装MySQL官方的 Yum Repository

[root@ccheng ~]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

(如果发现wget命令不能用则需要下载wget命令:yum -y install wget)

[root@ccheng ~]# yum -y install mysql57-community-release-el7-10.noarch.rpm

2、安装MySQL服务器。

[root@ccheng ~]# yum -y install mysql-community-server

3、MySQL数据库设置

首先启动MySQL

[root@ccheng ~]# systemctl start mysqld.service

[root@ccheng ~]# systemctl status mysqld.service
在这里插入图片描述

此时MySQL已经开始正常运行,不过要想进入MySQL还得先找出此时root用户的密码,通过如下命令可以在日志文件中找出密码:
[root@ccheng ~]# grep “password” /var/log/mysqld.log

发现此时的密码比较麻烦,在这里直接采用跳过初始密码的方式

4、初始密码忘记重置密码()
1.  [root@ccheng ~]# vi /etc/my.cnf,在[mysqld]中添加

skip-grant-tables
例如:
[mysqld]
skip-grant-tables
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

2.  重启mysql

[root@ccheng ~]# service mysql restart
#如果以上命令不能用则采用centos7用此命令重启
[root@ccheng ~]# systemctl restart  mysqld.service

3.  使用用户无密码登录

[root@ccheng ~]# mysql -uroot -p (直接点击回车,密码为空)

4. 选择数据库

mysql> use mysql;

5. 修改root密码

mysql> update user set authentication_string=password('123456') where user='root';

6 .刷新权限

mysql> flush privileges;

7 .退出

mysql> exit;

8 .删除第1部增加的配置信息
[root@ccheng ~]# vi /etc/my.cnf
删除此配置:skip-grant-tables

9 .重启mysql

[root@ccheng ~]# service mysql restart
#centos7用此命令重启
[root@ccheng ~]# systemctl restart  mysqld.service
5、登录mysql 用新密码123456登录之后
[root@ccheng ~]#  smysql -uroot -p
pwd:123456
6、查看当前数据密码设置等级
mysql> SHOW VARIABLES LIKE 'validate_password%';

发现等级过高,设置的简单密码不能使用:	修改数据库密码安全等级:
mysql> set global validate_password_policy=LOW; 
mysql> set global validate_password_length=6;

正式启用修改后的密码:
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456'; 

查看当前数据库命令:
show databases;

在此centos7配置mysql完成^ _ ^

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值