Databases: Difference between revisions

From Cheatsheet
Jump to navigationJump to search
Line 11: Line 11:
# Authenticate into a specific database
# Authenticate into a specific database
mysql -u MyUser -p MyDatabase;
mysql -u MyUser -p MyDatabase;
</syntaxhighlight>


<syntaxhighlight lang="bash">
# Switch to a different database
# Switch to a different database
USE MyDatabase;
USE MyDatabase;
Line 29: Line 31:
# Exit the MySQL CLI
# Exit the MySQL CLI
exit
exit
</syntaxhighlight>
<syntaxhighlight lang="bash">
# List created users
SELECT user FROM mysql.user;
</syntaxhighlight>
</syntaxhighlight>



Revision as of 14:33, 26 September 2023


MYSQL / MARIADB

# Activate the MySQL CLI (as user with proper permission)
mysql;

# Authenticate into the MySQL CLI
mysql -u MyUser -p;

# Authenticate into a specific database
mysql -u MyUser -p MyDatabase;
# Switch to a different database
USE MyDatabase;

# Show all databases;
SHOW DATABASES;

# Show all tables within the database
SHOW TABLES;

# Show information about the contents of a table
DESCRIBE users;

# Show indexes and additional information for a table
SHOW INDEXES FROM dogs;

# Exit the MySQL CLI
exit
# List created users
SELECT user FROM mysql.user;

Postgres

# Log into the Postgres CLI
psql

# List all databases
\l

# Connect to a database
-d mydatabase -U databaseuser –W

# Switch to the new database connection
\c mydatabase databaseuser

# List all tables
\dt

# Quit the Postgres CLI
\q