Advertisement
Justman10000

Manage MariaDB

Feb 21st, 2023 (edited)
1,307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.26 KB | None | 0 0
  1. // To install MariaDB
  2.  
  3. # Install dependencies
  4. apt install libncurses5 -y
  5.  
  6. # Create user
  7. adduser --gecos --disabled-login --disabled-password --no-create-home mysql
  8.  
  9. version=$(curl -s https://archive.mariadb.org/ | grep -oP '\d+\.\d+\.\d+' | sort -rV | head -n 1)
  10. wget https://archive.mariadb.org/mariadb-$version/bintar-linux-systemd-x86_64/mariadb-$version-preview-linux-systemd-x86_64.tar.gz
  11.  
  12. if [[ ! -f mariadb-$version-preview-linux-systemd-x86_64.tar.gz ]]; then
  13.     version=$(curl -s https://archive.mariadb.org/ | grep -oP '\d+\.\d+\.\d+' | sort -rV | head -n 1)
  14.     wget https://archive.mariadb.org/mariadb-$version/bintar-linux-systemd-x86_64/mariadb-$version-linux-systemd-x86_64.tar.gz
  15.  
  16.     gunzip mariadb-$version-linux-systemd-x86_64.tar.gz
  17.     tar xvf mariadb-$version-linux-systemd-x86_64.tar
  18.     mv mariadb-$version-linux-systemd-x86_64 mariadb
  19. else
  20.     gunzip mariadb-$version-preview-linux-systemd-x86_64.tar.gz
  21.     tar xvf mariadb-$version-preview-linux-systemd-x86_64.tar
  22.     mv mariadb-$version-preview-linux-systemd-x86_64 mariadb
  23. fi
  24.  
  25. ln -fs /usr/local/mariadb/bin/* /usr/bin
  26.  
  27. /usr/local/mariadb/scripts/mariadb-install-db --basedir=/usr/local/mariadb --datadir=/usr/local/mariadb/data
  28. chmod -R 777 /usr/local/mariadb
  29. ln -s /usr/local/mariadb /usr/local/mysql
  30. /usr/local/mariadb/bin/mariadbd-safe --datadir="/usr/local/mariadb/data" --pid-file="/usr/local/mariadb/data/`uname -n`.pid" "$@" &
  31. # Leave the question 'Enter current password for root' blank and answer the question 'Change the root password?' with 'n'
  32. /usr/local/mariadb/bin/mariadb-secure-installation
  33.  
  34. ln -s /usr/local/mariadb/data/`uname -n`.err /var/log/mariadb.log
  35.  
  36. # Now choose a username and password...
  37. username=
  38. password=
  39. ## You can use instead this, to let's generate a random username and password
  40. wget https://gist.githubusercontent.com/Justman100/239710c5764f6cae9b70a7daf042f70c/raw/a6d4802aa7e2ac1af4bb3a79ed481dd3f357b42f/grs.sh -O /usr/bin/grs
  41. chmod +x /usr/bin/grs
  42. username=$(grs 64)
  43. password=$(grs 64)
  44.  
  45. mariadb << EOF
  46. CREATE USER $username@localhost IDENTIFIED BY '$password';
  47. GRANT ALL PRIVILEGES ON *.* TO $username@localhost WITH GRANT OPTION;
  48. CREATE USER $username IDENTIFIED BY '$password';
  49. GRANT ALL PRIVILEGES ON *.* TO $username WITH GRANT OPTION;
  50. EOF
  51.  
  52. # Adding this to your `.bashrc` in the `/root` directory and restart your terminal
  53. export MYSQLCLIENT_CFLAGS="-I/usr/local/mariadb/include/mysql -I/usr/local/mariadb/include/mysql/mysql"
  54. export MYSQLCLIENT_LDFLAGS="-L/usr/local/mariadb/lib/ -lmariadb"
  55.  
  56. # To get all IPs which tried to connect with the MariaDB instance
  57. cat /var/log/mariadb.log | grep -ioP "'.+'@'.+'" | grep -ioP '\d+\.\d+\.\d+\.\d+'
  58.  
  59. // To uninstall MariaDB
  60. # Stop MariaDB
  61. kill $(cat /usr/local/mariadb/data/`uname -n`.pid)
  62. # Remove MariaDB
  63. rm -r /usr/local/mariadb
  64. # Remove binarys
  65. rm -r /usr/bin/aria*
  66. rm -r /usr/bin/garb*
  67. rm -r /usr/bin/galera*
  68. rm -r /usr/bin/innochecksum
  69. rm -r /usr/bin/maria*
  70. rm -r /usr/bin/mbstream
  71. rm -r /usr/bin/msql2mysql
  72. rm -r /usr/bin/myis*
  73. rm -r /usr/bin/my_print_defaults
  74. rm -r /usr/bin/myrocks_hotbackup
  75. rm -r /usr/bin/mysql*
  76. rm -r /usr/bin/mytop
  77. rm -r /usr/bin/perror
  78. rm -r /usr/bin/replace
  79. rm -r /usr/bin/resolveip
  80. rm -r /usr/bin/resolve_stack_dump
  81. rm -r /usr/bin/sst_dump
  82. rm -r /usr/bin/wsrep*
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement