D:\APP\mysql-8.0.32-winx64\mysql-8.0.32-winx64\bin>mysqld --initialize --console 2023-05-19T10:19:10.565838Z 0 [Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future release. Please use authentication_policy instead. 2023-05-19T10:19:10.565870Z 0 [System] [MY-013169] [Server] D:\APP\mysql-8.0.32-winx64\mysql-8.0.32-winx64\bin\mysqld.exe (mysqld 8.0.32) initializing of server in progress as process 22568 2023-05-19T10:19:10.589188Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. 2023-05-19T10:19:10.984526Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended. 2023-05-19T10:19:11.901049Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 2HJ>dktjatZQ
D:\APP\mysql-8.0.32-winx64\mysql-8.0.32-winx64\bin> 其中最后一行的password is generated for root@localhost: 2HJ>dktjatZQ 2HJ>dktjatZQ 是初始化密码 得找个地方复制好 后面要用
然后安装Mysqlmysqld --install mysql
1 2 3 4 5
D:\APP\mysql-8.0.32-winx64\mysql-8.0.32-winx64\bin>mysqld --install mysql The service already exists! The current server installed: D:\APP\mysql-8.0.32-winx64\mysql-8.0.32-winx64\bin\mysqld mysql
这里我装过了 所以显示文件已存在 如果你报error 看看是不是没有管理员的权限
启动mysqlnet start mysql
1 2 3 4 5 6 7
D:\APP\mysql-8.0.32-winx64\mysql-8.0.32-winx64\bin>net start mysql mysql 服务正在启动 . mysql 服务已经启动成功。
mysql好像是默认开机自启动的 所以不需要每次开机命令启动
关掉MySQL的命令(虽然不常用)``net stop mysql
1 2 3 4
D:\APP\mysql-8.0.32-winx64\mysql-8.0.32-winx64\bin>net stop mysql mysql 服务正在停止. mysql 服务已成功停止。
接下来登陆Mysqlmysql -uroot -p
1 2 3 4 5 6 7
D:\APP\mysql-8.0.32-winx64\mysql-8.0.32-winx64\bin>mysql -uroot -p Enter password:
D:\APP\mysql-8.0.32-winx64\mysql-8.0.32-winx64\bin>mysql -uroot -p Enter password: *************** Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.32 MySQL Community Server - GPL
Copyright (c) 2000, 2023, 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>
就登进来了
登陆进来后第一件事就是改密码 不改的话不管什么操作都报错 ALTER USER "root"@"localhost" IDENTIFIED BY "新密码";
1 2 3 4 5 6 7
例如: mysql> ALTER USER "root"@"localhost" IDENTIFIED BY "abc123456"; Query OK, 0 rows affected (0.02 sec)
mysql>
那么你的root登陆密码就是abc123456
随便查询个数据库``show databases;
1 2 3 4 5 6 7 8 9 10 11 12 13 14
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.02 sec)
mysql>
就搞定了
ps:如果输完一段命令 它换行又跳-> 是补充没结束的意思 末尾记得加;
1 2 3 4 5 6 7 8 9 10 11 12 13
mysql> show databases -> ; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.02 sec)
mysql>
另外给MySQL配置环境变量会变得很方便
1 2 3 4 5 6 7 8 9 10 11 12
平时如果直接打开命令提示符 登陆mysql
Microsoft Windows [版本 10.0.22621.1702] (c) Microsoft Corporation。保留所有权利。
C:\Users\Ganxy>mysql -uroot -p Enter password: *************** Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 8.0.32 MySQL Community Server - GPL
Copyright (c) 2000, 2023, 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.