How to create MySQL Database using matlab?
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am doing some data analytics using MySQL and Matlab. My program works fine if there is already an existing database present. But it doesn't work when there is not database for which I am trying to create connection. Now, what I want to do is to create a database with a fixed name if there is no database present in that name. I searched all over the internet and haven't found any option for that. May be I am missing something.
Additionally, I would like to create a table on the newly created database and store some random data on them. I can do this part. But I am stucked on the first part which is creating database programmatically using matlab.
Please note that, I have to use only matlab for this project. Any kind cooperation will be greatly appreciated.
2 Kommentare
James Johnson
am 2 Feb. 2018
Bearbeitet: James Johnson
am 2 Feb. 2018
I don't think Matlab CAN make a SQL database? Please let me know if you have solved this. I am working on similar issues. One can create an sqlite database, but one cannot store matrices or strings in it (as near as I can tell). You have to make the database elsewhere for anything other than sqlite.
I asked a related question and in that you can find some code that might get you started if you had given up in April.
Antworten (1)
Piyush Kumar
am 29 Okt. 2024
To programmatically create a MySQL database using MATLAB, follow these steps:
- Establish a Database Connection: First, connect to the MySQL server without specifying a database.
- Create the Database: Use SQL commands to create the database if it doesn't already exist.
% Establish a database connection
conn = database('', 'username', 'password', 'Vendor', 'MySQL', 'Server', 'localhost', 'PortNumber', 3306);
dbName = 'test';
% Form the SQL query
sqlCreateDB = sprintf('CREATE DATABASE IF NOT EXISTS %s', dbName);
execute(conn, sqlCreateDB);
close(conn);
The above code will create a database named "test" if it does not exist already. If the database exists, it will not create the database.
After creating this database, you can establish a new connection to this newly created database and execute other commands like create tables, fetching rows from tables etc.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Database Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!