命令行快速安装MySQL
Posted Mr.zhou_Zxy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了命令行快速安装MySQL相关的知识,希望对你有一定的参考价值。
第一步:
将下载好的mysql的版本文件放在自定义目录
第二步:
添加一个data文件夹和一个my.ini文件
需要注意的是设置MySQL安装目录和数据目录的时候,路径名用的是正斜杠
- my.ini文件内容
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8mb4
[mysqld]
# 设置3306端口
port = 10086
# 设置mysql的安装目录
basedir=D:/software/MySQL/mysql-8.0.27-winx64
# 设置mysql数据库的数据的存放目录
datadir=D:/software/MySQL/mysql-8.0.27-winx64/data
# 允许最大连接数
max_connections=20
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8mb4
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
wait_timeout=31536000
interactive_timeout=31536000
第三步:
以管理员身份运行cmd
第四步:
- 进入指定目录
C:\\Windows\\system32>cd D:\\software\\MySQL\\mysql-8.0.27-winx64\\data
- 初始化
D:\\software\\MySQL\\mysql-8.0.27-winx64\\bin>mysqld --initialize --console
2021-10-28T01:27:04.640310Z 0 [Warning] [MY-000081] [Server] option 'wait_timeout': unsigned value 31536000 adjusted to 2147483.
2021-10-28T01:27:04.640562Z 0 [System] [MY-013169] [Server] D:\\software\\MySQL\\mysql-8.0.27-winx64\\bin\\mysqld.exe (mysqld 8.0.27) initializing of server in progress as process 9432
2021-10-28T01:27:04.660209Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-10-28T01:27:05.256802Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-10-28T01:27:06.806077Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
2021-10-28T01:27:06.806249Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
2021-10-28T01:27:06.962565Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: sd_yZU>Ce3rl
- 安装
D:\\software\\MySQL\\mysql-8.0.27-winx64\\bin>mysqld install
Service successfully installed.
- 启动
D:\\software\\MySQL\\mysql-8.0.27-winx64\\bin>net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。
- 进入MySQL
D:\\software\\MySQL\\mysql-8.0.27-winx64\\bin>mysql -hlocalhost -uroot -p -P10086
Enter password: ************
Welcome to the MySQL monitor. Commands end with ; or \\g.
Your MySQL connection id is 8
Server version: 8.0.27
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> alter user 'root'@'localhost' identified with mysql_native_password by 'root';
Query OK, 0 rows affected (0.04 sec)
- 完成退出
mysql> exit;
Bye
以上是关于命令行快速安装MySQL的主要内容,如果未能解决你的问题,请参考以下文章