- 下载数据库mysql8.0.27, SQLyog,mysql-connector-odbc
强烈推荐从镜像下载
mysql-connector-odbc-8.0.27-winx64.msi
https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/Connector-ODBC/8.0/
mysql-8.0.27-winx64.msi
https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-8.0/ SQLyog,
https://github.com/webyog/sqlyog-community/wiki/Downloads
安装
以下命令通过cmd管理员方式
@1 mysqld -install
@2 mysqld --initialize --console
*需要记得最后产后的密码 A temporary password is generated for root@localhost:
@3 net start mysql
@4 mysql -u root -p
输入密码
@5 alter user user() identified by "123456"
修改密码
Or alter user ‘root’@‘localhost’ identified with mysql_native_password by ‘123456’;
配置完成之后可以新建自己的数据库
在qt中连接
QString dsn = "Driver={MySQL ODBC 8.0 UniCode Driver};"; // Driver is now {MySQL}
dsn.append("Server=127.0.0.1,3306;"); // IP,Port
dsn.append("Database=db_mt;"); //
dsn.append("Uid=root;"); // User
dsn.append("Pwd=123456;");
dsn.append("MULTI_HOST=1;");
QSqlDatabase db=QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName(dsn);
if(db.open()){
qDebug()<<"success open ";
db.close();
}else {
qDebug()<<"open failed";
}
也可以在管理工具中设置
QSqlDatabase db=QSqlDatabase::addDatabase("QODBC");
db.setPort(3306);
db.setDatabaseName("MTTEST");
db.setUserName("root");
db.setPassword("123456");
if(db.open()){
qDebug()<<"success open ";
db.close();
}else {
qDebug()<<"open failed";
}