Mysql Commands: Difference between revisions

From The Opensource Knowledgebase
Jump to navigation Jump to search
 
(2 intermediate revisions by the same user not shown)
Line 11: Line 11:
*Create database: param  
*Create database: param  
**Using defaults
**Using defaults
:: <code> mysql> CREATE DATABASE param; </code>
:: <code> MariaDB [(none)]> CREATE DATABASE param; </code>
:*Using specific parameters
:*Using specific parameters
:: <code> mysql> CREATE DATABASE param DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; </code>
:: <code> MariaDB [(none)]> CREATE DATABASE param DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; </code>
*Delete database: param
*Delete database: param
: <code> mysql> DROP DATABASE param;</code>
: <code> MariaDB [(none)]> DROP DATABASE param;</code>
*List the databases created in the database server
*List the databases created in the database server
: <code> SHOW DATABASES; </code>
: <code> MariaDB [(none)]> SHOW DATABASES; </code>
*Use a particular database and see all the tables in the database
*Use a particular database and see all the tables in the database
: <code> use param; </code>
: <code> MariaDB [(none)]> use param; </code>
: <code> MariaDB [param]> shwo tables; </code>
: <code> MariaDB [param]> show tables; </code>


=User Management=
=User Management=
Line 26: Line 26:
: <code> MariaDB [(none)]> mysqlselect host, user, password from mysql.user; </code>
: <code> MariaDB [(none)]> mysqlselect host, user, password from mysql.user; </code>
* Show grants to a user
* Show grants to a user
: <code> MariaDB [(none)]> HOW GRANTS FOR 'dbusername'@'%'; </code>
: <code> MariaDB [(none)]> SHOW GRANTS FOR 'dbusername'@'%'; </code>
Here dbusername is the name of the user that is used to handle database access
Here dbusername is the name of the user that is used to handle database access
*Revoke all grants to a user
*Revoke all grants to a user

Latest revision as of 08:41, 13 January 2020

Installation

  • Installation on ubuntu server through terminal
sudo apt install mariadb-server
sudo mysql_secure_installation
sudo systemctl status mariadb
  • Start or stop mariadb server services
sudo systemctl stop mariadb
sudo systemctl start mariadb

Database Management

  • Create database: param
    • Using defaults
MariaDB [(none)]> CREATE DATABASE param;
  • Using specific parameters
MariaDB [(none)]> CREATE DATABASE param DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
  • Delete database: param
MariaDB [(none)]> DROP DATABASE param;
  • List the databases created in the database server
MariaDB [(none)]> SHOW DATABASES;
  • Use a particular database and see all the tables in the database
MariaDB [(none)]> use param;
MariaDB [param]> show tables;

User Management

  • Show users
MariaDB [(none)]> mysqlselect host, user, password from mysql.user;
  • Show grants to a user
MariaDB [(none)]> SHOW GRANTS FOR 'dbusername'@'%';

Here dbusername is the name of the user that is used to handle database access

  • Revoke all grants to a user
MariaDB [(none)]> REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'dbusername'@'%';
  • Delete a user
MariaDB [(none)]> DROP USER 'dbusername'@'%';

Access Rights Management

Table Management

Backup Management