minhd
1/2/2018 - 4:43 AM

MySQL Snippets

User Management

CREATE USER 'testuser'@'ip' IDENTIFIED BY 'pass';
GRANT ALL ON *.* TO 'testuser'@'ip';
flush privileges;

Any host root

update user set host=’%’ where user=’root’ and host=’ubuntuserv’;
flush privileges;

Database Backup and Restore

mysqldump -u root -p --all-databases > all_dbs.sql
mysql -u root -p < all_dbs.sql

mysqldump -u {user} -p {database} | gzip > `date -I`.database.sql.gz
gzip -dc < `date -I`.{database}.sql.gz | mysql -u {user} -p {database}

Pipeviewer restore

pv mydump.sql.gz | gunzip | mysql -u root -p

Max allowed packet

SHOW VARIABLES LIKE 'max_allowed_packet'
SET GLOBAL max_allowed_packet=1073741824;

my.ini under [mysqld]
max_llowed_packet=500M