Commands for MySQL

31 || 0  || 2018-04-14 06:03:57 || root || || Bash

This snippet contains several useful shell commands related to MySQL. The document is periodically updated.

# Create dump of MySQL schema
mysqldump --host=HOST_URL --user=USERNAME --password=PASSWORD --add-drop-table SCHEMA_NAME --hex-blob > /tmp/DUMPNAME.sql

# Restore MySQL schema from a dump
mysql --host=HOST_URL --user=USERNAME --password=PASSWORD SCHEMA_NAME < /tmp/DUMPNAME.sql

# Create new MySQL schema
CREATE DATABASE `SCHEMA_NAME` /*!40100 DEFAULT CHARACTER SET utf8 */;

# Create new MySQL user
CREATE USER 'USER_NAME'@'localhost' IDENTIFIED BY 'password';

# Grant full access to MySQL user for specific database
GRANT ALL PRIVILEGES ON SCHEMA_NAME.* TO 'USER_NAME'@'localhost';