安装mysql5.7

安装mysql5.7

安装mysql源

1
rpm -Uvh  http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm

安装mysql

1
yum -y install mysql-community-server

启动

1
2
systemctl start mysqld
systemctl enable mysqld

查看日志,看临时密码

1
grep 'temporary password' /var/log/mysql.log

登录后修改

1
2
3
4
5
alter user user() identified by "123.Shui!!$#";
flush privileges;

或者
alter user 'root'@'localhost' identified by '123.Shui!!$#';

设置 root 远程访问,5.6之前可以直接通过修改表生效,5.7之后就不可以了

1
2
use mysql ;
update mysql.user set host="%" where user="root";

设置5.7 root 远程访问

1
2
3
grant all privileges on *.* to 'root'@'%' identified by '123.Shui!!$#' with grant option;

flush privileges #需要执行这个语句,要不然就要重启,8.0的mysql不用执行这句。

注意

官网

1
https://dev.mysql.com/doc/refman/5.7/en/grant.html

创建用户远程访问

1
2
3
4
5
create user 'test1' identified by '123.Yichen!!';     #密码不能太简单,8.0是可以简单
这是可以远程登录,但是没有权限。

GRANT ALL ON *.* TO 'test1'@'%';
这时候就可以了。

后期更换密码

1
2
3
alter user 'root'@'%' indentified by '123.Shui!!$#@';

注意这里不用使用user()函数,使用user()会是'root'@'localhost' 会报错,因为表里已经没有这个主机了。

忘记密码修改

1
2
3
4
vim /etc/my.cnf   (在[mysqld]参数组下添加)
skip-grant-tables #跳过授权表

重启mysql

登录 把user变里的authentication_string字段的内容清空。

1
2
3
mysql -u root 

update mysql.user set authentication_string='' where user='root' and host='%';

然后退出

退出,把Skip-grant-table语句删除,重新启动数据库

在重置密码

1
alter user'root'@'%' IDENTIFIED BY '123.Shui!!#@';

评论


:D 一言句子获取中...

加载中,最新评论有1分钟缓存...