Mysql安装与配置
mysql的安装和配置
软件下载
- Mysql5.7软件下载
- 下载后会得到zip 安装文件
- 解压的路径最好不要有中文和空格
- 我解压到 D:\mysql-5.7.19-winx64 目录下 【根据自己的情况来指定目录,尽量选择空间大的盘】
添加环境变量
- 电脑-属性-高级系统设置-环境变量,在Path 环境变量增加mysql的安装目录\bin目录, 如下图
软件安装
添加配置文件
-
在D:\mysql-5.7.19-winx64 目录下下创建 my.ini 文件, 需要我们自己创建
文件内容为:
[client] port=3306 default-character-set=utf8 [mysqld] # 设置为自己MYSQL的安装目录 basedir=D:\mysql-5.7.19-winx64\ # 设置为MYSQL的数据目录 datadir=D:\mysql-5.7.19-winx64\data\ port=3306 character_set_server=utf8 #跳过安全检查(就是无需密码登录,待会要注释掉) skip-grant-tables -
使用管理员身份打开 cmd , 并切换到 D:\mysql-5.7.19-winx64\bin 目录下, 执行mysqld -install
D:\mysql-5.7.19-winx64\bin>mysqld -install Service successfully installed. -
始化数据库: mysqld --initialize-insecure --user=mysql
D:\mysql-5.7.19-winx64\bin>mysqld --initialize-insecure --user=mysql -
启动mysql 服务: net start mysql 【停止mysql服务指令 net stop mysql】, 如果成功:
D:\mysql-5.7.19-winx64\bin>net start mysql MySQL 服务正在启动 . MySQL 服务已经启动成功。 -
进入mysql 管理终端: mysql -u root -p 【当前root 用户密码为 空】
D:\mysql-5.7.19-winx64\bin>mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.19 MySQL Community Server (GPL) Copyright (c) 2000, 2017, 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. -
修改root 用户密码
use mysql;
update user set authentication_string=password('sdy') where user='root' and Host='localhost';
上面的语句就是修改 root用户的密码为 hsp
注意:在后面需要带 分号,回车即可执行该指令
执行: flush privileges; 刷新权限
退出: quit
mysql> use mysql; Database changed mysql> use mysql; update user set authentication_string=password('sdy') where user='root' and Host='localhost'; Database changed Query OK, 1 row affected, 1 warning (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 1 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> quit Bye -
修改my.ini , 再次进入就会进行权限验证了
注释掉配置文件中这行
#skip-grant-tables -
重新启动mysql
net stop mysql
net start mysqlD:\mysql-5.7.19-winx64\bin>net stop mysql MySQL 服务正在停止. MySQL 服务已成功停止。 D:\mysql-5.7.19-winx64\bin>net start mysql MySQL 服务正在启动 . MySQL 服务已经启动成功。 -
再次进入Mysql, 输入正确的用户名和密码
D:\mysql-5.7.19-winx64\bin>mysql -u root -p Enter password: *** Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.19 MySQL Community Server (GPL) Copyright (c) 2000, 2017, 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> 安装配置结束
安装过程中,一定要按照步骤来,不然会错误.
如果真的错误了, 清除mysql服务, 再次安装.
清除mysql服务指令:
sc delete mysql 【删除已经安装好的mysql服务 ,提示:慎重!】
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】