mariadb - bunnyamin/bunnix GitHub Wiki

MariaDB

Administrate

Command Example
Install root # './bin/mysqladmin' -u root [-h <HOSTNAME>] password '<PASSWORD>'
User, create, ordinary CREATE USER '<USER>'@'<HOST>' [IDENTIFIED BY '<PASSWORD>'];
GRANT CREATE, DROP, DELETE, INSERT, SELECT, UPDATE ON * . * TO '<USER>'@'<HOST>';
GRANT ALL PRIVILEGES ON * . * TO ''<USER>'@'<HOST>';
GRANT SHUTDOWN ON * . * TO ''<USER>'@'<HOST>';
FLUSH PRIVILEGES;
User, rename RENAME user '<user>' TO '<USER>'@'<HOST>';
User, delete DROP USER '<USER>'@'<HOST>';

Setup

1. account

  1. Create mariadb group # groupadd mariadb.
  2. Create mariadb user # useradd -r -g mariadb -s /bin/false mariadb.
    • -r, --system create a system account
    • -g, --gid GROUP name or ID of the primary group of the new account
    • -s, --shell SHELL login shell of the new account
  3. Change ownership to mariadb for all extracted files # chown -R mariadb:mariadb <MARIADB DIRECTORY>.

SELinux

If SELinux is enabled additional modifications may be required.

2. database

  1. Install mariadb database # <MARIADB DIRECTORY>/scripts/mysql_install_db --user=mariadb --basedir="<MARIADB DIRECTORY>" --datadir="<DATABASE DIRECTORY>"
    • --user=mariadb The login username to use for running mysqld. Files and directories created by mysqld will be owned by this user. You must be root to use this option. By default mysqld runs using your current login name and files and directories that it creates will be owned by you.
    • --basedir=/usr The path to the MariaDB installation directory.
    • --datadir=/var/lib/mariadb The path to the MariaDB data directory.
    • --ldata=path The path to the MariaDB data directory. Same as --datadir.
    • --no-defaults Don't read default options from any option file.
    • NOTE Make sure the path to datadir allows +x for the MariaDB user.
  2. Modify ownership to mariadb for database # chown -R mariadb:mariadb <DATABASE DIRECTORY>.
  3. Modify permission for database chmod -R 775 <DATABASE DIRECTORY>.
    • The mariadb user and group rwx, all other users rx.
  4. Assign user sudo privileges to mysqld_safe # user ALL=(mariadb) NOPASSWD: <MARIADB DIRECTORY>/mysqld_safe.
    • An ordinary user requires to sudo as user mariadb in order to start the server.
  5. Modify permission for files that files that are owned by mariadb but are allowed to be edited by an other user for administrative purposes, such as the .mariadb.cnf file; assign a group permission to the file that is shared by mariadb and the user, for example, users.

3. start server

  • $ sudo -u mariadb <MARIADB DIRECTORY>/mysqld_safe --defaults-file="~/.mariadb.cnf" --ledir="/mariadb/bin/"
    • NOTE Ensure the path to log allows rw for the mariadb user.
    • The defaults-file must come before ledir.

Error, problem, troubleshooting

Event Error Cause Remedy
bin/mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory Build libncurses.so.5. and ln -s /ncurses/libncurses.so.5 /usr/lib/libncurses.so.5.
Cannot open table mysql/(innodb_(index_stats|table_stats) | s lave_(master_info|relay_log_info|worker_info) Delete all binlogs. (1) Shutdown server. (2) Delete any and all:
gtid_slave_pos.frm
gtid_slave_pos.ibd
innodb_index_stats.frm
innodb_index_stats.ibd
innodb_table_stats.frm
innodb_table_stats.ibd
(3) Start server mysql_upgrade --defaults-file=mariadb.cnf. (4) Restart server.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) Reset root password. (1) Stop mysqld, and restart with skip grant mysqld_safe --defaults-file=~/mariadb.cnf --ledir=<MARIADB DIRECTORY>/bin --skip-grant-tables. (2) Start mariadb, and update root password mysql --defaults-file=~/mariadb.cnf.
MariaDB [(none)]> use mysql;
MariaDB [mysql]> UPDATE user SET password=PASSWORD('<NEW PASSWORD>') WHERE User='root';
MariaDB [mysql]> FLUSH PRIVILEGES;
MariaDB [mysql]> quit;
(3) Stop server running skip grant, start it as usual.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2 'No such file or directory')
mysql_install_db # chown: changing ownership of '<DATABASE DIRECTORY>': Operation not permitted
Cannot change ownership of the database directories to the 'mysql' user. Check that you have the necessary permissions and try again.
Executing mysql_install_db as ordinary user.
⚠️ **GitHub.com Fallback** ⚠️