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

Microsoft Windows Server 2012 R2 Standard Evaluation Product Key

Microsoft Windows Server 2012 R2 Standard Evaluation D2N9P-3P6X9-2R39C-7RTCD-MDVJX DBGBW-NPF86-BJVTX-K3WKJ-MTB6V

ManageEngine ServiceDesk Plus - Reset password

Let's reset the default administrator's password to 'admin'

Check and install php7.0-mbstring extention on Ubuntu 16.04 and Microsoft Windows

While learning Facebook SDK for PHP I overlooked one of system requirements preventing my code from running on my host. That is The mbstring extension. Facebook SDK for PHP's system requirements Check if mbstring is enabled root@ubuntu001:~# php -a Interactive mode enabled php > echo extension_loaded('mbstring'); php >exit root@ubuntu001:~# apt-cache search php7 | grep mbstring php7.0-mbstring - MBSTRING module for PHP root@ubuntu001:~# Install php7.0-mbstring root@ubuntu001:~# apt-get install php7.0-mbstring Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required:   fontconfig-config fonts-dejavu-core libfontconfig1 libgd3 libjbig0   libjpeg-turbo8 libjpeg8 libmcrypt4 libtiff5 libvpx3 libxpm4 Use 'apt autoremove' to remove them. The following additional packages will be installed:   libapache2-mod-php7.0 php7.0-cli ph