-
February 22nd, 2024, 04:11 PM
#1
[RESOLVED] how to "create" or "make" Schema
i thought setSchema("mydatabase"); create mydatabase, but it does not.
what c++ code will create mydatabase?
everything i find, just connects to mydatabase.
-
February 23rd, 2024, 02:27 AM
#2
Re: how to "create" or "make" Schema
Victor Nijegorodov
-
February 25th, 2024, 04:57 PM
#3
Re: how to "create" or "make" Schema
 Originally Posted by VictorN
create database using cpp?
-
February 26th, 2024, 02:16 AM
#4
Re: how to "create" or "make" Schema
 Originally Posted by micha_eleric
create database using cpp?
Again: you have to send SQL command with "CREATE DATABASE ..." to your DBMS.
See also https://www.google.com/search?q=CREA...t=gws-wiz-serp
Last edited by VictorN; February 26th, 2024 at 02:18 AM.
Reason: link was added
Victor Nijegorodov
-
February 28th, 2024, 07:50 PM
#5
Re: how to "create" or "make" Schema
one of the videos somehow ran, but did not have a type before function def, guessing it was suppose to be void.
const char* database = "cppdb";
conn = mysql_real_connect(conn, hostname, username, password, database, port, unixsocket, clientflag);
but database is not created until after mysql_real_connect is called. based on function not having type before def, maybe video is missing something.
createdatabase(MYSQL* conn) is called using conn from mysql_real_connect.
-
February 28th, 2024, 08:25 PM
#6
Re: how to "create" or "make" Schema
001 Create a Database from the ground up in C++, is so blurry, no clue what code is, all the way to the end
-
February 28th, 2024, 10:05 PM
#7
Re: how to "create" or "make" Schema
answer to question is: mysql_query(conn, "CREATE DATABASE mydatabase"); , but has to have a database to create a database. mysql is there by default
#include <iostream>
#include <mysql.h>
const char* hostname = "localhost";
const char* username = "root";
const char* password = "";
const char* database = "mysql"; // has to have a database to create a database. mysql is there by default
unsigned int port = 3306;
const char* unixsocket = NULL;
unsigned long clientflag = 0;
MYSQL* connectdatabase()
{
MYSQL* conn;
conn = mysql_init(0);
conn = mysql_real_connect(conn, hostname, username, password, database, port, unixsocket, clientflag);
if(conn)
{
std::cout << "Connected " << conn << std::endl;
return conn;
}
else
{
std::cout << "not connected " << conn << std::endl;
return conn;
}
}
int main(int argc, char *argv[])
{
MYSQL* conn = connectdatabase();
mysql_query(conn, "CREATE DATABASE mydatabase");
return 0;
}
Last edited by micha_eleric; February 28th, 2024 at 10:14 PM.
-
February 28th, 2024, 11:35 PM
#8
Re: [RESOLVED] how to "create" or "make" Schema
found
int mysql_create_db(MYSQL *mysql, const char *db)
highlights like development environment recognizes it, but is not found by compiler
-
February 29th, 2024, 02:41 AM
#9
Re: how to "create" or "make" Schema
 Originally Posted by micha_eleric
... has to have a database to create a database.
You probably meant "has to have a DBMS to create a database". Didn't you?
Last edited by VictorN; February 29th, 2024 at 09:29 AM.
Victor Nijegorodov
-
February 29th, 2024, 08:56 PM
#10
Re: how to "create" or "make" Schema
 Originally Posted by VictorN
You probably meant "has to have a DBMS to create a database". Didn't you?
only if database named "mysql" is a DBMS.
"mysql" was shown when "MariaDB [(none)]> SHOW DATABASES;"
-
March 1st, 2024, 02:26 AM
#11
Re: how to "create" or "make" Schema
Victor Nijegorodov
-
March 1st, 2024, 07:25 PM
#12
Re: how to "create" or "make" Schema
 Originally Posted by VictorN
MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mydatabase |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.001 sec)
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|