CentOs7下安装Mysql

wget http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm 1
2.安装YUM库

rpm -ivh mysql57-community-release-el7-10.noarch.rpm 1
3.安装数据库

yum -y install mysql-community-server 1
4.完成安装,重启mysql

systemctl restart mysqld 1
此时MySQL已经开始正常运行,不过要想进入MySQL还得先找出此时root用户的密码,通过如下命令可以在日志文件中找出密码:

grep “password” /var/log/mysqld.log

[root@hadoop8 ~]# grep “password” /var/log/mysqld.log
2018-10-13T08:33:27.994868Z 1 [Note] A temporary password is generated
for root@localhost: yj0v.0w*ywPk 1 2 3 4
5.复制粘贴上边的密码进入数据库

mysql -uroot -p 1 输入初始密码,此时不能做任何事情,因为MySQL默认必须修改密码之后才能操作数据库修改密码命令:

ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘123456’; Your password
does not satisfy the current policy requirements 1 2
6.解决报错 修改密码策 因为当前的密码太复杂不方便后期做实验,所以使用命令修改密码策略两种方式:

mysql> set global validate_password_policy=0; Query OK, 0 rows
affected (0.00 sec) 1 2 mysql> set global
validate_password_policy=LOW; Query OK, 0 rows affected (0.00 sec) 1 2
注:密码策略分四种 1、OFF(关闭) 2、LOW(低) 3、MEDIUM(中) 4、STRONG(强) 上边改完策略之后我们在改长度

mysql> SET GLOBAL validate_password_length=6; Query OK, 0 rows
affected (0.00 sec) 注:执行完初始化命令后需要输入数据库root用户密码 1 2 3 密码策略修改完以后可以修改密码:

ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘123456’; 1 退出重启。

查询用户信息 mysql> select User,Host from user;

更新用户信息 mysql> update user set Host=’%’ where User = ‘root’ ;

删除用户信息 mysql> delete from user where user=‘root’ and host=‘127.0.0.1’;

刷新信息 mysql> flush privileges;

你可能感兴趣的:(CentOs7下安装Mysql)