hj_mysql5.7.36免安装版
官网下载地址 -> https://dev.mysql.com/downloads/mysql/ 选择 Windows (x86, 64-bit), ZIP Archive;
解压文件->配置系统环境变量到bin目录. 系统变量: MY_SQL57_HOME D:\SYS\ISP\mysql-5.7.36-winx64 Path: %MY_SQL57_HOME\bin
如果电脑缺乏 msvcr120.dll等俩文件,去Microsoft官网(https://www.microsoft.com/zh-cn/download/confirmation.aspx?id=40784)
单机手动下载,有三个.exe文件. 下载 执行;
新建my.ini文件,内容如下.放置到解压后与 bin平级的目录下.
[mysql] # 设置mysql客户端默认字符集 default-character-set=utf8 [mysqld] # 服务端使用的字符集默认为8比特编码的latin1字符集 character-set-server=utf8 #设置3308端口 默认是3306 port=3308 # 设置mysql的安装目录 basedir="D:\SYS\ISP\mysql-5.7.36-winx64" # 设置mysql数据库的数据的存放目录 datadir="D:\SYS\ISP\mysql-5.7.36-winx64\data" # 设置mysql数据库的数据存放临时文件目录 tmpdir="D:\SYS\ISP\mysql-5.7.36-winx64\data" log-error="D:\SYS\ISP\mysql-5.7.36-winx64\data\mysql57_error.log" # 设置mysql的socket目录 socket="D:\SYS\ISP\mysql-5.7.36-winx64\data\mysql.sock" # 允许最大连接数 max_connections=200 # 创建新表时将使用的默认存储引擎 default-storage-engine=INNODB # 其他先使用默认配置咯~
以管理员的身份运行cmd,切入到bin目录下---->
1->mysqld --initialize -insecure --user=hj_mysql 创建data目录,服务命名为 hj_mysql ;
ps:mysqld --initialize -insecure 这个命令会生成无密码的root用户,而命令 mysqld --initialize自动生成带随机密码的root用户
2->mysqld --install hj_mysql --defaults-file="D:\SYS\ISP\mysql-5.7.36-winx64\my.ini"
若报错: The service already exists! 需要执行以下操作,然后彻底干掉mysql残留文件,注册表. 然后再执行安装
D:\SYS\ISP\mysql-5.7.36-winx64\bin>sc query mysql 查询mysql服务 mysql/hj_mysql 服务名 SERVICE_NAME: mysql TYPE : 10 WIN32_OWN_PROCESS STATE : 1 STOPPED WIN32_EXIT_CODE : 0 (0x0) SERVICE_EXIT_CODE : 0 (0x0) CHECKPOINT : 0x0 WAIT_HINT : 0x0 D:\SYS\ISP\mysql-5.7.36-winx64\bin>sc delete mysql 删除服务 [SC] DeleteService 成功
D:\SYS\ISP\mysql-5.7.36-winx64\bin>mysqld -install hj_mysql --defaults-file="D:\SYS\ISP\mysql-5.7.36-winx64\bin\my.ini"
Service successfully installed.
ps: 若是报错 mysql57 服务正在启动 . mysql57 服务无法启动。 服务没有报告任何错误。
可运行 mysqld --console 命令.根据里面信息再排错,或者查看mysql57_error.log日志...
例如:Can't open and lock privilege tables: Table 'mysql.user' doesn't exist 等,若是这个错,删除掉data目录,
执行 mysqld --initialize --user=hj_mysql --console 重新生成data文件.
3->启动服务 net strat hj_mysql mysql -uroot -p 进入.若老是报错ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061),
请千万主意是不是没带端口号...如果改了默认端口的话.. net strat hj_mysql -> mysql -uroot -P3308 -p
也可用免密方式进入再置空密码,流程如下;
net stop hj_mysql 停止服务 ,然后运行 mysqld --console --skip-grant-tables --shared-memory 如下显示:
D:\SYS\ISP\mysql-5.7.36-winx64\bin>net stop hj_mysql hj_mysql 服务正在停止. hj_mysql 服务已成功停止。 D:\SYS\ISP\mysql-5.7.36-winx64\bin>mysqld --console --skip-grant-tables --shared-memory 2021-12-07T09:07:54.182983Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2021-12-07T09:07:54.183042Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled 2021-12-07T09:07:54.183571Z 0 [Note] mysqld (mysqld 5.7.36) starting as process 6380 ... 2021-12-07T09:07:54.187450Z 0 [Note] InnoDB: Mutexes and rw_locks use Windows interlocked functions 2021-12-07T09:07:54.188386Z 0 [Note] InnoDB: Uses event mutexes 2021-12-07T09:07:54.188801Z 0 [Note] InnoDB: _mm_lfence() and _mm_sfence() are used for memory barrier 2021-12-07T09:07:54.189158Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11 2021-12-07T09:07:54.189461Z 0 [Note] InnoDB: Number of pools: 1 2021-12-07T09:07:54.189757Z 0 [Note] InnoDB: Not using CPU crc32 instructions 2021-12-07T09:07:54.191818Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M 2021-12-07T09:07:54.196132Z 0 [Note] InnoDB: Completed initialization of buffer pool 2021-12-07T09:07:54.240463Z 0 [Note] InnoDB: Highest supported file format is Barracuda. 2021-12-07T09:07:54.271125Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables 2021-12-07T09:07:54.271694Z 0 [Note] InnoDB: Setting file '.\ibtmp1' size to 12 MB. Physically writing the file full; Please wait ... 2021-12-07T09:07:54.279638Z 0 [Note] InnoDB: File '.\ibtmp1' size is now 12 MB. 2021-12-07T09:07:54.280919Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active. 2021-12-07T09:07:54.281177Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active. 2021-12-07T09:07:54.281740Z 0 [Note] InnoDB: Waiting for purge to start
再另开一个cmd窗口---> mysql -uroot -p 无密码直接回车(这可不带端口号).
D:\SYS\ISP\mysql-5.7.36-winx64\bin>mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.36 MySQL Community Server (GPL) Copyright (c) 2000, 2021, Oracle and/or its affiliates. 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> use mysql Database changed mysql>
密码置空: mysql -u root -p 直接回车进入. use mysql update user set authentication_string='' where user='root'; flush privileges; exit;
D:\SYS\ISP\mysql-5.7.36-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.36 MySQL Community Server (GPL) Copyright (c) 2000, 2021, Oracle and/or its affiliates. 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> ; ERROR: No query specified mysql> update user set authentication_string='' where user='root'; ERROR 1046 (3D000): No database selected mysql> use mysql Database changed mysql> update user set authentication_string='' where user='root'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> exit; Bye
关闭免密模式的cmd窗口.启动服务 net start hj_mysql mysql -uroot -p
修改密码 alter user 'root'@'localhost' identified with mysql_native_password by '123456';
flush privileges; exit;
mysql> alter user 'root'@'localhost' identified with mysql_native_password by '123456'; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec) mysql> ps:mysql cmd下若语句写错一直->这样,可 Ctrl+c 同时按退出那错误语句.
大功告成~