该文针对绿色版MySQL而写
添加配置
在MySQL安装或解压(这是我的安装目录D:\TOOL\mysql-5.6.37-winx64)的目录下的my-default.ini文件中添加MySQL安装路径
[mysqld]
basedir= D:\TOOL\mysql-5.6.37-winx64(此路径为MySQL安装目录或称为解压的目录)
datadir= D:\TOOL\mysql-5.6.37-winx64\data(此目录是MySQL存放数据目录,在MySQL安装目录或解压的目录下会有data,如果没有直接创建一个即可)
登陆MySQL
以管理员的身份运行cmd,在cmd进入到MySQL的bin目录下运行dos命令(Window 10 系统最好打开Window Powershell(管理员)然后编辑命令)
1. mysqld install (添加MySQL服务) 注:Window 10 输入命令为:.\mysqld install
出现Service successfully installed.即可
2. net start mysql(启动MySQL服务)
MySQL 服务正在启动 .
MySQL 服务已经启动成功。
启动成功则可以登陆账号了
mysql-uroot -p 注:Window 10输入命令为:.\ mysql-uroot -p
Enter password: (初次安装是没有密码的直接回车键即可)
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.37 MySQL CommunityServer (GPL)
Copyright (c) 2000, 2017, Oracle and/orits affiliates. All rights reserved.
Oracle is a registered trademark ofOracle Corporation and/or its
affiliates. Other names may betrademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c'to clear the current input statement.
出现以上信息代表登陆成功
设置密码
set password for root@localhost = password("1234");
注:root为账号,1234为新密码
Query OK, 0 rows affected (0.00 sec)
Exit(退出MySQL)
net stop mysql(停止MySQL服务)
mysqld remove(删除服务) 注:Window 10 输入命令为:.\ mysqldremove
exit(退出cmd窗口)
重新再进行一遍登陆MySQL即可
修改密码
在登陆的情况下改密码:
mysqladmin-uroot -p1234 password 123456 (root为账号,1234为旧密码,123456为新密码)
不登录的情况下改密码:
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;。
7. 改密码:update user setpassword=password("123") where user="root";(别忘了最后加分号)。
8. 刷新权限(必须步骤):flush privileges; 。
9. 退出 quit。
9. 注销系统,再进入,使用用户名root和刚才设置的新密码123登录。
查询该MySQL的用户
selecthost,user,password from mysql.user;
修改用户权限
update mysql.user set host = '%' wherepassword='1234';
也可
update mysql.user set host = '%' where user=’root’;
注:有可能会存在多个root用户所以将条件设为密码比较精准
如有不妥欢迎各大佬评论然后进行修改