Skip to main content

MySQL: Notes

Illustrated: MySQL Logo

Ways to check MySQL version

mysql --version
mysql -V
dpkg -l 'mysql-sever'
mysql -u root -p
How to check MySQL version: mysql --version
How to check MySQL version: mysql --version

Database folder

On Microsoft Windows, by default, MySQL save databases in this folder:

%ProgramData%\MySQL\MySQL Server 5.5\data

Check databases' size

SELECT table_schema AS "Database name", SUM(data_length + index_length) / 1024 / 1024 AS "Size (MB)" FROM information_schema.TABLES GROUP BY table_schema;

Export database schema

$ mysqldump -u root -p --no-data wordpress1001 > c:\backup\schema-wordpress1001.sql
Enter password: ****************

Create a dedicated user to backup databases

Give credit to: http://www.fromdual.com/privileges-of-mysql-backup-user-for-mysqldump

Create dedicated mysql user and grant privileges to run backup

$ mysql -u root -p
CREATE USER 'backupdb'@'localhost' IDENTIFIED BY 'passwordhere';
GRANT SELECT,SHOW VIEW,RELOAD,REPLICATION CLIENT,EVENT,TRIGGER ON *.* TO 'backupdb'@'localhost';
GRANT LOCK TABLES ON *.* TO 'backupdb'@'localhost';
FLUSH PRIVILEGES;
QUIT;

Backup all databases

mysqldump -u backupdb -p --all-databases | gzip -c > /backup/databases-$(date '+%Y%m%d%H%M').sql.gz
Backup all databases using dedicated mysql user backupdb
Backup all databases using dedicated mysql user backupdb

Check databases' size

$ mysql -u root -p
SELECT table_schema AS "Database", 
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS "Size(MB)" 
FROM information_schema.TABLES 
GROUP BY table_schema;

Change user's password

ALTER USER 'username'@'localhost' IDENTIFIED BY 'Enter-new-password';

MySQL/MariaDB Client

apt install mycli

MySQL Shell for VS Code

Popular posts from this blog

hmailserver: Notes from the field

hmailserver is one of free open source mail servers running on Microsoft Windows operating system.

stegseek: Notes

StegCracker has been retired following the release of StegSeek, which will blast through the rockyou.txt wordlist within 1.9 second as opposed to StegCracker which takes ~5 hours.

VMware ESXi host loads ipmi_si_drv too long

Workaround: remove ipmi_si_drv esxcli software vib remove --dry-run --vibname ipmi-ipmi-si-drv esxcli software vib remove --vibname ipmi-ipmi-si-drv ~ # esxcli software vib remove --dry-run --vibname ipmi-ipmi-si-drv Removal Result    Message: Dryrun only, host not changed. The following installers will be applied: [BootBankInstaller]    Reboot Required: true    VIBs Installed:    VIBs Removed: VMware_bootbank_ipmi-ipmi-si-drv_39.1-4vmw.550.0.0.1331820    VIBs Skipped: ~ # ~ # esxcli software vib remove --vibname ipmi-ipmi-si-drv Removal Result    Message: The update completed successfully, but the system needs to be rebooted for the changes to be effective.    Reboot Required: true    VIBs Installed:    VIBs Removed: VMware_bootbank_ipmi-ipmi-si-drv_39.1-4vmw.550.0.0.1331820    VIBs Skipped: ~ #