H:\mysql-9.1.0-winx64\bin>mysqld --initialize --console 2024-12-25T07:24:13.742985Z 0 [System] [MY-015017] [Server] MySQL Server Initialization - start. 2024-12-25T07:24:13.747449Z 0 [System] [MY-013169] [Server] H:\mysql-9.1.0-winx64\bin\mysqld.exe (mysqld 9.1.0) initializing of server in progress as process 18948 2024-12-25T07:24:13.761946Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. 2024-12-25T07:24:13.938955Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended. 2024-12-25T07:24:15.411887Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: -M6xjww6A:jl 2024-12-25T07:24:17.307449Z 0 [System] [MY-015018] [Server] MySQL Server Initialization - end.
先复制好这个初始化密码:M6xjww6A:jl
1
2024-12-25T07:24:15.411887Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: -M6xjww6A:jl
如果已经初始化删除 data 目录重新初始化即可。
4. 安装 MySQL 服务并启动
1
mysqld --install mysql
5. 启动 MySQL 服务
1
net start mysql
6. 连接 MySQL
1
mysql -u 用户名 -p
首次登录:回车后输入初始化化密码即可
1 2 3 4 5 6 7 8 9 10 11 12 13
H:\mysql-9.1.0-winx64\bin>mysql -uroot -p Enter password: ************ Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 10 Server version: 9.1.0
Copyright (c) 2000, 2024, 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.
7. 修改密码
连接完成后才能修改密码:
1
ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';
QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7 open failed... QSqlQuery::exec: database not open QSqlQuery::prepare: database not open QSqlError("", "Driver not loaded", "Driver not loaded")
原因是:未能加载 QMYSQL 驱动
使用 Qt sql 模块来操作 MySQL 数据库,需要三个库文件来支持,分别为:libmysql.dll、qsqlmysql.dll 和 qsqlmysqld.dll ,三个文件缺一不可。