Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

MariaDB Management


May 16, 2021 MariaDB


Table of contents


Before attempting to run MariaDB, first determine its current state, run it, or close it. T here are three options for starting and stopping MariaDB -

  • Run mysqld (MariaDB script).
  • Run mysqld_safe startup script.
  • Run mysql.server startup script.

If you install MariaDB in a non-standard location, you may need to edit the location information in the script file. S imply add the Stop parameter to the script to stop MariaDB.

If you want to start it automatically under Linux, add the startup script to the init system. E ach distribution has a different process. S ee the system documentation.

Create a user account

Create a new user account using the following code -

'newusername'@'localhost' IDENTIFIED BY 'userpassword';

This code does not have any permissions to add a row to the user table. Y ou can also choose to use hash values as passwords. G rant user rights using the following code -

GRANT SELECT, INSERT, UPDATE, DELETE ON database1 TO 'newusername'@'localhost';

Other permissions include every command or action that is possible in MariaDB. A fter you create the user, execute the FLUSH PRIVILEGES command to refresh the authorization table. T his allows the use of user accounts.

Profile

After building on Unix/Linux, you should edit the profile "/etc/my.conf" to show the following -

# Example mysql config file.
# You can copy this to one of:
# /etc/my.cnf to set global options,
# /mysql-data-dir/my.cnf to get server specific options or
# ~/my.cnf for user specific options.

#

# One can use all long options that the program supports.
# Run the program with --help to get a list of available options

# This will be passed to all mysql clients
[client]
#password = my_password
#port = 3306
#socket = /tmp/mysql.sock

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

# The MySQL server
[mysqld]
#port = 3306
#socket = /tmp/mysql.sock
temp-pool

# The following three entries caused mysqld 10.0.1-MariaDB (and possibly other
   versions) to abort...
# skip-locking
# set-variable = key_buffer = 16M
# set-variable = thread_cache = 4

loose-innodb_data_file_path = ibdata1:1000M
loose-mutex-deadlock-detector
gdb

######### Fix the two following paths

# Where you want to have your database
data = /path/to/data/dir

# Where you have your mysql/MariaDB source + sql/share/english
language = /path/to/src/dir/sql/share/english

[mysqldump]
quick
MariaDB
8
set-variable = max_allowed_packet=16M
[mysql]
no-auto-rehash

[myisamchk]
set-variable = key_buffer = 128M

Edit the lines "data" and "language" to match your environment.

After the file is modified, navigate to the source directory and do the following -

./scripts/mysql_install_db --srcdir = $PWD --datadir = /path/to/data/dir --
   user = $LOGNAME

If you add datadir to your profile, ignore the $PWD variable. M ake sure to use "$LOGNAME" when running version 10.0.1 mariaDB.

Manage commands

Check out the following list of important commands you'll use frequently when using MariaDB:

  • USE (database name) - Set the current default database.

  • SHOW DATABASES - Lists the current database on the server.

  • SHOW TABLES - Lists all non-temporary tables.

  • SHOW COLUMNS FROM (table name) - Provides column information about the specified table.

  • SHOW INDEX FROM TABLENAME (table name) - Provides table index information related to the specified table.

  • SHOW TABLE STATUS LIKE (table name) - A table that provides information about a non-temporary table, as well as a pattern that the LIKE clause displays after getting the table name.