1. 在启动mysql服务时出现该错误:
本地计算机上的mysql服务启动停止后,某些服务在未由其他服务或程序使用时将自动停止。
打开CMD窗口, 请以管理员权限运行!
首先,你需要把原来的服务删除:
mysql --remove mysql;
初始化命令:
mysqld --initialize-insecure --user=mysql
注册mysql服务:
mysqld --install
启动服务:
net start mysql
停止服务:
net stop mysql
注意:
mysql的安装目录下:
你需要清空data目录。
如果没有data目录,请自行创建一个空目录,起名为data!
然后在bin目录下运行以上命令。
2. mysql设置账号密码
mysql初始密码为空: mysql -u root - p
mysql如何修改root用户的密码
方法1: 用SET PASSWORD命令
首先登录MySQL。
格式:mysql> set password for 用户名@localhost = password('新密码');
例子:mysql> set password for root@localhost = password('123456');
方法2:用mysqladmin
格式:mysqladmin -u用户名 -p旧密码 password 新密码
例子:mysqladmin -uroot -p123 password 123456
方法3:用UPDATE直接编辑user表
首先登录MySQL。
mysql> use mysql;
mysql> update user set password=password('123456') where user='root' and host='localhost';
mysql> flush privileges;
方法4:在忘记root密码的时候,可以这样
以windows为例:
1. 关闭正在运行的MySQL服务。
2. 打开DOS窗口,转到mysql\bin目录。
3. 输入mysqld --skip-grant-tables 回车。--skip-grant-tables 的意思是启动MySQL服务的时候跳过权限表认证。
4. 再开一个DOS窗口(因为刚才那个DOS窗口已经不能动了),转到mysql\bin目录。
5. 输入mysql回车,如果成功,将出现MySQL提示符 >。
6. 连接权限数据库: use mysql; 。
6. 改密码:update user set password=password("123456") where user="root";(别忘了最后加分号) 。
7. 刷新权限(必须步骤):flush privileges; 。
8. 退出 quit。
9. 注销系统,再进入,使用用户名root和刚才设置的新密码123登录。
3. Mysql 修改用户密码报错ERROR 1054 (42S22): Unknown Column 'Password' In 'Field List'解决办法
5.7版本下的mysql数据库下已经没有password这个字段了,password字段改成了authentication_string
所以更改语句替换为update user set authentication_string=password('123456') where user='root' and host='localhost';
4. 执行第三步骤时报错:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '('123456') where user='root' and host='localhost'' at line 1
网上好多都说是引号问题,结果不是引号问题。
而是MYSQL8.0以上版本正确修改ROOT密码应该:
alter user 'root'@'localhost' identified by '123456';
flush privileges;
浙公网安备 33010602011771号