Databases: Difference between revisions

From Cheatsheet
Jump to navigationJump to search
Line 2: Line 2:


== MYSQL / MARIADB ==
== MYSQL / MARIADB ==
=== Login ===
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
# Activate the MySQL CLI (as user with proper permission)
# Activate the MySQL CLI (as user with proper permission)
Line 13: Line 14:
</syntaxhighlight>
</syntaxhighlight>


=== Movement and checks ===
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
# Switch to a different database
# Switch to a different database
Line 36: Line 38:
# List created users
# List created users
SELECT user FROM mysql.user;
SELECT user FROM mysql.user;
# See privileges for the user johan
SHOW GRANTS FOR johan;
</syntaxhighlight>
</syntaxhighlight>



Revision as of 14:36, 26 September 2023


MYSQL / MARIADB

Login

# 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;

Movement and checks

# 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;

# See privileges for the user johan
SHOW GRANTS FOR johan;

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