mysql
MySQL tips.
More information you can found here
Connect
mysql -u root --host myserver.com -p
CRUD
Create
Retrieve
Update
Delete
- Delete row
 
- Drop table
 
Permissions
- Show grants for current user
 
- Show all user privileges from information_schema
 
- Grant privileges
 
- Revoke privileges
 
- Change password
 
errors migrating from mysql 5.7 to 8:
Authentication plugin 'caching_sha2_password' cannot be loaded:
Admin
- Show table sizes
 
Metrics
- Show main metrics
 
- show System metrics
 
select name,status,count,avg_count,max_count,subsystem from INNODB_METRICS where subsystem="os" or subsystem='file_system';
- Open files
 
- Table sizes
 
SELECT  table_schema as `Database`, table_name AS `Table`, round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB` FROM information_schema.TABLES ORDER BY (data_length + index_length) DESC;
- proccess running (queries)
 
- w/o sleeping queries
 
Management
- Kill queries running:
 
- kill all queries
 
Backup/Restore
Reference: https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html
- Dump the entire DB
 
mysqldump -h 127.0.0.1 -P 3306 -u root -p --no-tablespaces --column-statistics=0 --all-databases > bkp-all.sql
- Dump specific table
 
mysqldump -h 127.0.0.1 -P 3306 -u root -p --databases rundeck --no-tablespaces --column-statistics=0 > bkp-rundeck.sql
- Restore DB (rundeck)
 
GUI
phpMySQLADmin
- Docker: https://hub.docker.com/r/phpmyadmin/phpmyadmin/
 
References:
- https://dev.mysql.com/doc/mysql-getting-started/en/