Create new database from command line
To create a new database from the command line, you'll need to use a database management system (DBMS) such as MySQL, PostgreSQL, or SQLite. Here are the steps for each:
MySQL
- Open a terminal or command prompt.
- Install MySQL if you haven't already. You can download it from the official MySQL website.
- Start the MySQL server by running the command
mysql -uroot -p
(replaceroot
with your MySQL username andp
with your password). - Create a new database by running the command
CREATE DATABASE mydatabase
(replacemydatabase
with the name of your new database). - Verify that the database was created by running the command
SHOW DATABASES;
.
PostgreSQL
- Open a terminal or command prompt.
- Install PostgreSQL if you haven't already. You can download it from the official PostgreSQL website.
- Start the PostgreSQL server by running the command
pg_ctl start
(on macOS or Linux) ornet start postgres
(on Windows). - Create a new database by running the command
createdb mydatabase
(replacemydatabase
with the name of your new database). - Verify that the database was created by running the command
psql -l
(list all databases).
SQLite
- Open a terminal or command prompt.
- Install SQLite if you haven't already. SQLite is usually included with most operating systems, but you can also download it from the official SQLite website.
- Create a new database by running the command
sqlite3 mydatabase.db
(replacemydatabase.db
with the name of your new database). - Verify that the database was created by running the command
.tables
(list all tables in the database).
Note: In SQLite, the database file is created automatically when you run the sqlite3
command. You don't need to create a separate database management system like MySQL or PostgreSQL.
That's it! You should now have a new database created from the command line.