Mysql5.7 绿色版安装
Mysql5.7 绿色版安装
绿色版下载#
安装步骤#
- 解压mysql-5.7.18-winx64.zip 到指定文件夹(根据自己情况确定)
- 进入文件夹mysql-5.7.18-winx64
- 创建名为
data
的文件夹(若文件夹已存在,则清空文件夹中的文件)
# 进入文件夹 cd mysql-5.7.18-winx64 # 查看目录信息 dir # 判断有没有data,如果没有,则创建data文件夹 mkdir data # 如果有,清空data文件夹 del data
启动及配置Mysql#
-
以管理员权限运行cmd,并进入
mysql-5.7.18-winx64/bin
目录下 -
安装Mysql服务: cmd中输入
mysqld.exe –install
,安装成功会出现Service successfully installed
的提示字样D:\tools\mysql-5.7.18-winx64\bin> mysqld.exe -install Service successfully installed. -
初始化数据库: cmd中输入
mysqld --initialize-insecure --user=mysql --explicit_defaults_for_timestamp
(运行务必检测data文件夹中没有文件),这个没有任何返回值 -
启动mysql: cmd中输入
net start mysql
, 启动成功会出现mysql 服务已经启动成功
的提示字样D:\tools\mysql-5.7.18-winx64\bin> net start mysql MySQL 服务正在启动 . MySQL 服务已经启动成功。 -
测试mysql : cmd中输入
mysql.exe -uroot -p
, 接下来会让你输入密码,没有密码直接回车就行,到这里就证明mysql安装是没有问题的D:\tools\mysql-5.7.18-winx64\bin>mysql.exe -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.18 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编码为UTF8,在
mysql-5.7.18-winx64
目录下创建名为my.ini
的文件,文件内容如下[mysqld] character-set-server=utf8 [mysql] default-character-set=utf8 -
查看mysql修改前编码
mysql> show variables like 'character%'; +--------------------------+----------------------------------------------+ | Variable_name | Value | +--------------------------+----------------------------------------------+ | character_set_client | gbk | | character_set_connection | gbk | | character_set_database | latin1 | | character_set_filesystem | binary | | character_set_results | gbk | | character_set_server | latin1 | | character_set_system | utf8 | | character_sets_dir | D:\tools\mysql-5.7.18-winx64\share\charsets\ | +--------------------------+----------------------------------------------+ 8 rows in set, 1 warning (0.00 sec) -
重启mysql服务
# 进入bin目录 cd bin/ # 重启服务 mysqld.exe restart -
查看mysql修改后编码
mysql> show variables like 'character%'; +--------------------------+----------------------------------------------+ | Variable_name | Value | +--------------------------+----------------------------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | latin1 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | latin1 | | character_set_system | utf8 | | character_sets_dir | D:\tools\mysql-5.7.18-winx64\share\charsets\ | +--------------------------+----------------------------------------------+ 8 rows in set, 1 warning (0.00 sec) -
修改mysql密码
# 进入名为mysql的数据库 use mysql; # 修改mysql密码为 `123123` update user set authentication_string=PASSWORD("123123") where user="root"; # 刷新权限 flush privileges; 返回结果
mysql> use; ERROR: USE must be followed by a database name mysql> use mysql; Database changed mysql> update user set authentication_string=PASSWORD("123123") where user="root"; Query OK, 1 row affected, 1 warning (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 1 mysql> flush privileges; Query OK, 0 rows affected (0.03 sec) -
测试mysql密码
# 退出mysql quit; # 进入mysql mysql.exe -uroot -p123123 // -u 指定登录用户 -p指定该用户密码 返回结果
D:\tools\mysql-5.7.18-winx64\bin>mysql.exe -uroot -p123123 mysql: [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 10 Server version: 5.7.18 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服务
mysqld.exe –remove -
停止MySQL服务
net stop mysql -
忘记root账户密码
- 在
my.ini
中[mysqld]下添加一行skip-grant-tables
- 重启mysql服务,参考启动及配置mysql下第8点
- 在cmd中执行
mysql -uroot -p
进入mysql - 修改root账户密码, 参考启动及配置mysql下第10点
- 退出mysql, 将
my.ini
文件中刚才加入的skip-grant-tables
删掉,保存文件重启mysql服务即可
- 在
-
修改mysql访问权限,解决只允许localhost访问的问题
-
第一种解决方案: 改表法(不建议)
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> use mysql; Database changed mysql> update user set host = '%' where user ='root'; // 修改root用户可以以任何地址访问mysql服务 Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> flush privileges; //刷新权限 Query OK, 0 rows affected (0.02 sec) -
第二种解决方案:授权法(建议)
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> grant all privileges on *.* to 'root'@'%' identified by '123123'; //赋予root用户以密码为123123查看所有库 Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> flush privileges; // 刷新权限 Query OK, 0 rows affected (0.00 sec) -
关闭授权
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> revoke all on *.* from root@'%'; //撤销root用户的授权 Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
-
作者:jruing
出处:https://www.cnblogs.com/jruing/p/15108525.html
版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。
本文来自博客园,作者:Jruing,转载请注明原文链接:https://www.cnblogs.com/jruing/p/15108525.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!