linux:mariadb:mariadb-queries
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| linux:mariadb:mariadb-queries [2021/03/01 19:38] – oscar | linux:mariadb:mariadb-queries [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ===== MariaDB Common Queries ===== | ||
| - | ===== Query Databases ===== | ||
| - | < | ||
| - | MariaDB [(none)]> | ||
| - | +--------------------+ | ||
| - | | Database | ||
| - | +--------------------+ | ||
| - | | information_schema | | ||
| - | | mysql | | ||
| - | | nextcloud | ||
| - | | performance_schema | | ||
| - | | sitedatabase | ||
| - | +--------------------+ | ||
| - | </ | ||
| - | ===== Select a database ===== | ||
| - | < | ||
| - | MariaDB [(none)]> | ||
| - | Reading table information for completion of table and column names | ||
| - | You can turn off this feature to get a quicker startup with -A | ||
| - | Database changed | ||
| - | MariaDB [sitedatabase]> | ||
| - | </ | ||
| - | |||
| - | |||
| - | ===== Working with databases ===== | ||
| - | Show all available databases in the current MySQL database server | ||
| - | SHOW DATABASE; | ||
| - | Create a database with a specified name if it does not exist in the database server | ||
| - | CREATE DATABASE [IF NOT EXISTS] database_name; | ||
| - | Use a database or change the current database to another database that you are working with: | ||
| - | USE database_name; | ||
| - | Drop a database with a specified name permanently. All physical files associated with the database will be deleted. | ||
| - | DROP DATABASE [IF EXISTS] database_name; | ||
| - | ===== Working with tables ===== | ||
| - | Show all tables in a current database. | ||
| - | SHOW TABLES; | ||
| - | Create a new table | ||
| - | CREATE TABLE [IF NOT EXISTS] table_name( column_list ); | ||
| - | Add a new column into a table: | ||
| - | ALTER TABLE table | ||
| - | ADD [COLUMN] column_name; | ||
| - | Drop a column from a table: | ||
| - | ALTER TABLE table_name | ||
| - | DROP [COLUMN] column_name; | ||
| - | Add index with a specific name to a table on a column: | ||
| - | ALTER TABLE table | ||
| - | ADD INDEX [name](column, | ||
| - | Add primary key into a table: | ||
| - | ALTER TABLE table_name | ||
| - | ADD PRIMARY KEY (column_name, | ||
| - | Remove the primary key of a table: | ||
| - | ALTER TABLE table_name | ||
| - | DROP PRIMARY KEY; | ||
| - | Drop a table: | ||
| - | DROP TABLE [IF EXISTS] table_name; | ||
| - | Show the columns of a table: | ||
| - | DESCRIBE table_name; | ||
| - | Show the information of a column in a table: | ||
| - | DESCRIBE table_name column_name; | ||
| - | ===== Query Users ===== | ||
| - | < | ||
| - | MariaDB [(none)]> | ||
| - | +-----------+----------+-------------------------------------------+ | ||
| - | | host | user | password | ||
| - | +-----------+----------+-------------------------------------------+ | ||
| - | | localhost | root | *AF926838A9A0501BA7017D135C123C007497F85B | | ||
| - | | localhost | www-data | *AF926838A9A0501BA7017D135C123C007497F85B | | ||
| - | | localhost | nc-user | ||
| - | +-----------+----------+-------------------------------------------+ | ||
| - | |||
| - | MariaDB [(none)]> | ||
| - | +----------+--------------+-----------+ | ||
| - | | User | Db | Host | | ||
| - | +----------+--------------+-----------+ | ||
| - | | nc-user | ||
| - | | www-data | sitedatabase | localhost | | ||
| - | +----------+--------------+-----------+ | ||
| - | </ | ||
| - | ===== Create Users ===== | ||
| - | < | ||
| - | CREATE USER ' | ||
| - | CREATE USER ' | ||
| - | </ | ||
| - | ===== Query Users Rights ===== | ||
| - | < | ||
| - | MariaDB [(none)]> | ||
| - | +------------------------------------------------------------------------------------------------+ | ||
| - | | Grants for root@localhost | ||
| - | +------------------------------------------------------------------------------------------------+ | ||
| - | | GRANT ALL PRIVILEGES ON *.* TO ' | ||
| - | | GRANT PROXY ON '' | ||
| - | +------------------------------------------------------------------------------------------------+ | ||
| - | |||
| - | MariaDB [(none)]> | ||
| - | +-----------------------------------------------------------------------------------------------------------------+ | ||
| - | | Grants for www-data@localhost | ||
| - | +-----------------------------------------------------------------------------------------------------------------+ | ||
| - | | GRANT USAGE ON *.* TO ' | ||
| - | | GRANT ALL PRIVILEGES ON `sitedatabase`.* TO ' | ||
| - | +-----------------------------------------------------------------------------------------------------------------+ | ||
| - | |||
| - | MariaDB [(none)]> | ||
| - | +----------------------------------------------------------------------------------------------------------------+ | ||
| - | | Grants for nc-user@localhost | ||
| - | +----------------------------------------------------------------------------------------------------------------+ | ||
| - | | GRANT USAGE ON *.* TO ' | ||
| - | | GRANT ALL PRIVILEGES ON `nextcloud`.* TO ' | ||
| - | +----------------------------------------------------------------------------------------------------------------+ | ||
| - | </ | ||
| - | ===== Grand Users Rights ===== | ||
| - | < | ||
| - | GRANT ALL PRIVILEGES ON `sitedatabase`.* TO ' | ||
| - | GRANT ALL PRIVILEGES ON `nextcloud`.* TO ' | ||
| - | </ | ||
| - | ===== Migrate Databases ===== | ||
| - | Dump the databases on the original server. Better extract them one-by-one so we don't migrate anything unnecessary. To dump as single databases, use the following commands: | ||
| - | # mysqldump -u root -p --all-databases > all_databases.sql | ||
| - | # mysqldump -u [user] -p --opt [database name] > database_name.sql | ||
| - | | ||
| - | # mysqldump -u root -p --opt sitedatabase > sitedatabase_dump.sql | ||
| - | # mysqldump -u root -p --opt nextcloud > nextcloud_dump.sql | ||
| - | |||
| - | Once the dump is completed, you are ready to transfer the databases. But databases need to be created first on target server. | ||
| - | # mysql -u root -p | ||
| - | CREATE DATABASE sitedatabase; | ||
| - | CREATE DATABASE nextcloud; | ||
| - | quit; | ||
| - | Retore the data to the newly creates databases: | ||
| - | # mysql -u [user] -p --all-databases < all_databases.sql | ||
| - | # mysql -u [user] -p newdatabase < DUMP-SITE-DATABASE.sql | ||
| - | | ||
| - | # mysql -u root -p sitedatabase < sitedatabase_dump.sql | ||
| - | # mysql -u root -p nextcloud < nextcloud_dump.sql | ||
linux/mariadb/mariadb-queries.1614627512.txt.gz · Last modified: (external edit)
