一,MySQL8.0.*zip版本安装步骤。

1. 下载

https://dev.mysql.com/archives/get/p/23/file/mysql-8.0.24-winx64.zip

注现在最新的版本是8.0.24

2. 解压

mysql-8.0.24-winx64.zip解压到 E:\Tools\mysql\mysql-latest 目录下

3. 打开cmd命令控制台,输入以下命令。

切记使用windows中的cmd命令行。

  1. e:
  2. cd \
  3. cd E:\Tools\mysql\mysql-latest\bin
  4. rem 初始化数据库目录,账号为root,无密码. 执行后mysql目录下将会多出一个data文件夹。
  5. E:\Tools\mysql\mysql-latest\bin>mysqld --initialize-insecure

4. 安装数据库系统服务,输入以下命令。

  1. @echo off
  2. echo install mysql:
  3. pushd %~dp0\bin
  4. echo "%~dp0\bin"
  5. mysqld --install mysql_3306
  6. popd
  7. echo sleep 2秒钟
  8. ping 127.0.0.1 -n 1 -w 2000 > nul
  9. echo Starting mysql_3306:
  10. echo 启动数据库服务
  11. net start mysql_3306
  12. pause

5. 登录数据库服务器

  1. #rem 直接登录无密码
  2. E:\Tools\mysql\mysql-latest\bin>mysql -u root
  3. rem 查看当前版本号
  4. mysql>select version();
  5. rem 查看登录账号
  6. mysql>show user();
  7. rem 查看所有数据库
  8. mysql>show databases;
  9. rem 建立数据库
  10. mysql>create database db;

6. 退出卸载

  1. rem 退出客户端
  2. mysql>exit
  3. rem 停止服务
  4. E:\Tools\mysql\mysql-latest\bin>net stop mysql
  5. rem 卸载服务
  6. E:\Tools\mysql\mysql-latest\bin>mysqld --remove

7. 修改root密码为123456

连接到mysql

  1. E:\Tools\mysql\mysql-latest\bin\mysql -uroot
  2. ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';


方法二、还有一种方法

下载以后将安装包解压到任意文件夹,我这里解压到E:\Tools\mysql\mysql-latest

安装

E:\Tools\mysql\mysql-latest里面建立一个空文件夹data,如果已经有这个文件夹就不用进行这一步

建立一个my.ini文件,用记事本打开,复制以下代码进去

  1. [mysqld]
  2. # 设置3306端口
  3. port=3306
  4. # 设置mysql的安装目录
  5. basedir=E://Tools//mysql//mysql-latest
  6. # 设置mysql数据库的数据的存放目录
  7. datadir=E://Tools//mysql//mysql-latest//data # 注意要双//
  8. # 允许最大连接数
  9. max_connections=200
  10. # 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
  11. max_connect_errors=10
  12. # 服务端使用的字符集默认为utf8mb4 新版本的MySQL 字符集以更改为utf8mb4
  13. character-set-server=utf8mb4
  14. # 创建新表时将使用的默认存储引擎
  15. default-storage-engine=INNODB
  16. # 默认使用“mysql_native_password”插件认证
  17. default_authentication_plugin=mysql_native_password
  18. character-set-client-handshake = FALSE
  19. character-set-server = utf8mb4
  20. collation-server = utf8mb4_bin
  21. init_connect='SET NAMES utf8mb4'
  22. # Remove leading # and set to the amount of RAM for the most important data
  23. # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
  24. innodb_buffer_pool_size = 128M
  25. # Remove leading # to turn on a very important data integrity option: logging
  26. # changes to the binary log between backups.
  27. # log_bin
  28. # These are commonly set, remove the # and set as required.
  29. # server_id = .....
  30. # Remove leading # to set options mainly useful for reporting servers.
  31. # The server defaults are faster for transactions and fast SELECTs.
  32. # Adjust sizes as needed, experiment to find the optimal values.
  33. join_buffer_size = 128M
  34. sort_buffer_size = 16M
  35. read_rnd_buffer_size = 16M
  36. sql_mode=traditional
  37. [mysql]
  38. # 设置mysql客户端默认字符集
  39. default-character-set=utf8mb4
  40. [client]
  41. default-character-set = utf8mb4
  42. # 设置mysql客户端连接服务端时默认使用的端口
  43. port=3306


配置环境变量

右键计算机->属性->高级系统设置->高级->环境变量,在系统变量中添加一个名叫 MYSQL_HOME 的变量,修改Path变量,在末尾添加 %MYSQL_HOME%\bin,以管理员身份运行cmd命令,并将路径换到mysqlbin目录下,初始化数据库,运行命令:

  1. bin\mysqld --initialize-insecure --console
  1. E:\Tools\mysql\mysql-latest>bin\mysqld --initialize-insecure --console
  2. 2021-07-10T05:43:08.816199Z 0 [System] [MY-013169] [Server] E:\Tools\mysql\mysql-latest\bin\mysqld.exe (mysqld 8.0.25) initializing of server in progress as process 15860
  3. 2021-07-10T05:43:08.889111Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
  4. 2021-07-10T05:43:16.428759Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
  5. 2021-07-10T05:43:38.797280Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
  6. E:\Tools\mysql\mysql-latest>

安装服务

运行命令:mysqld –install, 至此mysql就安装完毕了

  1. bin\mysqld --install "MySql_3306" --defaults-file="E:/Tools/mysql/mysql-latest/my.ini"

image.png

测试是否安装成功

  • 启动mysql服务命令

    1. net start MySql_3306

    image.png

  • 停止mysql服务命令

    1. net stop MySql_3306

更改密码

假设要把密码改成123456, 运行cmd,在bin目录下运行命令:

  1. bin\mysql -u root -p

image.png
输入原密码
输入语句:

  1. ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

image.png

备注:8.0之前版本,忘记密码修改方法

  • 找到bin目录:mysqld —skip-grant-tables
  • 重新在开一个cmd窗口
  • 找到bin目录:mysql就进入登陆状态了
  • 5.7.22修改密码语句:update user set authentication_string=password(‘123456’) where user=’root’ and host=’localhost’;
  • 5.6.修改密码语句:update user set password=password(‘123456’) where user=’root’ and host=’localhost’; (我没有实验过,网上都是这么写的)

原文链接

https://www.cnblogs.com/activiti/p/10538169.html https://www.cnblogs.com/1285026182YUAN/p/10422133.html