MySQL: Difference between revisions

From Chorke Wiki
Jump to navigation Jump to search
Line 71: Line 71:
==Workbench==
==Workbench==
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
curl -fsSL https://repo.mysql.com/RPM-GPG-KEY-mysql-2023\
| sudo tee /etc/apt/keyrings/mysql.asc >/dev/null


DISTRIBUTION=$(. /etc/os-release && echo "${VERSION_CODENAME}");\
cat << SRC | sudo tee /etc/apt/sources.list.d/mysql.list >/dev/null
deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/mysql.asc] http://repo.mysql.com/apt/ubuntu/ ${DISTRIBUTION} mysql-tools
# deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/mysql.asc] http://repo.mysql.com/apt/ubuntu/ ${DISTRIBUTION} mysql-8.4-lts
# deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/mysql.asc] http://repo.mysql.com/apt/ubuntu/ ${DISTRIBUTION} mysql-apt-config
SRC
echo 'apt-get update;echo;apt-get install -y mysql-workbench-community'|sudo bash
</syntaxhighlight>
</syntaxhighlight>



Revision as of 22:10, 9 November 2024

sudo apt-get install mariadb-server mariadb-client
sudo systemctl enable --now mariadb
systemctl status mariadb
mariadb --version
sudo vim /etc/mysql/mariadb.conf.d/50-server.cnf
sudo systemctl restart mariadb.service
systemctl status mariadb.service
sudo mysql_secure_installation

Authorization

MySQL » Auth » Unix

sudo su
cat << DDL | mysql
CREATE USER 'chorke'@'localhost' IDENTIFIED VIA unix_socket;
GRANT ALL PRIVILEGES ON *.* TO 'chorke'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
DDL

MySQL » Auth » Local

cat << DDL | mysql
CREATE DATABASE IF NOT EXISTS chorke_orgwiki;
CREATE USER 'chorke_orgwiki'@'localhost' IDENTIFIED BY 'sadaqah!';
GRANT ALL PRIVILEGES ON chorke_orgwiki.* TO 'chorke_orgwiki'@'localhost';
FLUSH PRIVILEGES;
DDL

MySQL » Auth » Remote

cat << DDL | mysql
CREATE DATABASE IF NOT EXISTS chorke_orgwiki;
CREATE USER 'chorke_orgwiki'@'%' IDENTIFIED BY 'sadaqah!';
GRANT ALL PRIVILEGES ON chorke_orgwiki.* TO 'chorke_orgwiki'@'%';
FLUSH PRIVILEGES;
DDL

Backup Restore

BACKUP_DATE_TIME="$(date +'%Y%m%d-T%H%M')-Z$(date +'%z'|tr '+-' 'PM')"
echo -n password: ;read -s MYSQL_PWD;export MYSQL_PWD; echo
# password: sadaqah!

mysql     -h127.0.0.1 -P3306 -uchorke -Dchorke_orgwiki
mysqldump -h127.0.0.1 -P3306 -uchorke   chorke_orgwiki > ./chorke_orgwiki-${BACKUP_DATE_TIME}.dump
mysql     -h127.0.0.1 -P3306 -uchorke -Dchorke_orgwiki <   chorke_orgwiki-20241010-T1010-ZP0600.dump

Workbench

curl -fsSL https://repo.mysql.com/RPM-GPG-KEY-mysql-2023\
 | sudo tee /etc/apt/keyrings/mysql.asc >/dev/null

DISTRIBUTION=$(. /etc/os-release && echo "${VERSION_CODENAME}");\
cat << SRC | sudo tee /etc/apt/sources.list.d/mysql.list >/dev/null
deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/mysql.asc] http://repo.mysql.com/apt/ubuntu/ ${DISTRIBUTION} mysql-tools
# deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/mysql.asc] http://repo.mysql.com/apt/ubuntu/ ${DISTRIBUTION} mysql-8.4-lts
# deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/mysql.asc] http://repo.mysql.com/apt/ubuntu/ ${DISTRIBUTION} mysql-apt-config
SRC

echo 'apt-get update;echo;apt-get install -y mysql-workbench-community'|sudo bash

Playground

SELECT @@character_set_database, @@collation_database;
SHOW CHARACTER SET LIKE 'utf%';
SHOW CHARACTER SET;
show databases;
use academia;
show tables;
SELECT sysdate();
SELECT curdate();
SELECT now();

gpg --keyring /usr/share/keyrings/mysql-apt-config.gpg --no-default-keyring --export -a > mysql.asc
gpg --enarmor /usr/share/keyrings/mysql-apt-config.gpg
          cat /usr/share/keyrings/mysql-apt-config.gpg.asc

References