1. 安装以后查看服务是否自启动![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/b869fce8381d0fcb8604d5288a4ff0d7.png)
systemctl list-unit-files|grep mysql
启动mysql,无法登陆
解决方法:mysqld --user=mysql --skip-grant-tables --skip-networking &
2. 修改密码
password 字段不存在
解决方法:修改my.conf文件 ,添加如下
网上查了一下据说5.7 版本password 字段改成authentication_string password函数还是原来的password函数
mysql> update user set authentication_string=password('123') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
//以上为百度情况,不适于本人情况
//以下为自己的方法,不建议这么做,可跳过这一步
update mysql.user set authentication_string='' where user='root';
但是登录以后又出现,没有权限,需要替换密码,例如show databases;
mysql> use mysql;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. //报错
//修改替换密码的代码
alter user 'root'@'localhost' identified by 'your_replace_passwd';
解决方法:建议不知道规则可以设置一个复杂的密码,如: MqA@#?137&65
其实,涉及validate_password_policy
修改密码以后,可以使用以下查看
show variables like 'validate_password%'
网上的指导:
但自己的情况并不是这样,发现设置以后根本不能设置简单密码,甚至不可以密码明文登录(即-p后显示的加密码,不加空格)
//通过以下代码修改变量的值
set global validate_password_policy=0;
由图可见变量命名规则都不一样,存在两种类型,上图已经修改了validate_password.length和validate_password.policy
虽然设置了 validate_password.length=1,但由于validate_password.number_count/validate_password.special_char_count/validate_password.mixed_case_count=1
将其中一种类型命名规则的以上变量都赋值为0,set global validate_password.length=1;即可成功!!!
//现在即可设置最简单的密码了
alter user 'root'@'localhost' identified by '123';