Mysql的安装 Linux CentOS7

1、使用 yum 安装 mysql 客户端、服务端
yum -y install mysql-server
yum -y install mysql
安装完成之后,敲 mysql ,提示 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) 访问拒绝,需要输入密码
查阅资料得知,mysql 5.7版本提高了安全性,默认安装后会有一个初始的密码,存于/root/.mysql_secret 文件中 但是我在目录下并没有发现这个文件。运行find / -name .mysql_secret也没有找到。

2、修改Mysql配置文件,使mysql跳过用户验证。mysql配置文件默认是:/etc/my.conf,在[mysqld]节点下添加skip-grant-tables

3、执行systemctl restart mysqld.service,重启mysql服务。

4、执行mysql,直接进入mysql程序(mysql>的状态)

5、执行SQL,修改mysql密码update mysql.user set authentication_string = password('此处填写你的密码') where user = 'root' and Host = 'localhost';

执行SQLflush privileges;

6、quit;退出Mysql客户端,重启Mysql服务(systemctl restart mysqld.service)重新使用密码连接mysql -uroot -p

7、此时操作数据库,提示必须先设置密码
使用set password设置密码:
set password = password('设置一个较为复杂的密码')
如果密码强度不够,会设置失败

8、添加root用户远程允许连接:
grant all privileges on *.* to 'root'@'%' identified by '该用户的密码' with grant option;
其中,%表示不限连接Host,也可以写成一个IP(xx.xx.xx.xx)形式

9、另附 mysql 修改字符编码 

http://www.ha97.com/5359.html.

https://www.cnblogs.com/jentary/p/6655471.html.

评论区
回复