Mac下修改mysql初始密码和Windows忘记密码的处理

时间:2022-01-17 00:33:51
修改mysql的密码有很多方式,这里是直接修改mysql 数据库里面的user表的user字段值为root对应的authentication_string字段的值步骤:1.Mac下安装好mysql后,启动mysql(系统便好设置里面启动mysql,然后Start MYSQL Server) 2.进入终端输入命令:PATH=”$PATH":/usr/local/mysql/bin 3.由于刚刚安装好的mysql密码为空,输入命令:mysql -u root -p  按回车即可登录4.显示所有数据库,输入命令:show databases;
5.进入到名为mysql的数据库6.显示出mysql数据库里面的表, 有一个user表,里面就存储的是mysql用户名,密码7.打印user表结构
8.更新authentication_string(相当于windows里面的password字段)字段,此处要用PASSWORD()函数修改至此,mysql初始密码就修改完成了,之后就可以登录试试了添加内容:
关于Windows下面安装mysql5.6后忘记密码怎么重置的问题
1.密码错误的时候会显示:
 mysql -uroot -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
2.停止服务:
net stop mysql;
3.进入到skip-grant-tables模式:
mysqld safe --skip-grant-tables
4.此时登录mysql是不会需要密码
指令mysql就可以进入mysql数据库
进入mysql系统数据库:
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
修改root账户密码:
mysql> update user set password=password("12345") where user="root";
Query OK, 4 rows affected (0.02 sec)
Rows matched: 4 Changed: 4 Warnings: 0
刷新权限:
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
停止mysql进程:
Stopped mysqld safe --skip-grant-tables
启动mysql:
net start mysql;
Starting MySQL SUCCESS!
使用刚才修改的密码进入mysql:
[root@oraserver139 ~] mysql -u root -p 12345
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.15
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
mysql> SET PASSWORD = PASSWORD('12345');
Query OK, 0 rows affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
修改完成;