Last active
May 8, 2020 09:12
-
-
Save stormwild/ca7badceef5ebbbf6448 to your computer and use it in GitHub Desktop.
MySQL - Create Database Statement with Unicode Support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE SCHEMA `dbname` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ; | |
CREATE USER 'username'@'%' IDENTIFIED BY 'password'; | |
GRANT ALL PRIVILEGES ON dbname.* TO 'username'@'%' WITH GRANT OPTION; | |
FLUSH PRIVILEGES; | |
mysql> create database mydb; | |
mysql> use mydb; | |
mysql> source db_backup.dump; | |
-- Backup database | |
mysqldump --opt -u [uname] -p[pass] [dbname] > [backupfile.sql] | |
-- Backup a database | |
mysqldump -u root -p Tutorials > tut_backup.sql | |
-- Backup a specific table | |
mysqldump -u root -p Tutorials php_tutorials asp_tutorials > tut_backup.sql | |
-- Backup multiple databases | |
mysqldump -u root -p --databases Tutorials Articles Comments > content_backup.sql | |
-- Backup all databases | |
mysqldump -u root -p --all-databases > alldb_backup.sql | |
--add-drop-table: Tells MySQL to add a DROP TABLE statement before each CREATE TABLE in the dump. | |
--no-data: Dumps only the database structure, not the contents. | |
--add-locks: Adds the LOCK TABLES and UNLOCK TABLES statements you can see in the dump file. | |
-- Backup to gzip file | |
mysqldump -u [uname] -p[pass] [dbname] | gzip -9 > [backupfile.sql.gz] | |
-- Restore database | |
mysql -u [uname] -p[pass] [db_to_restore] < [backupfile.sql] | |
-- Restore a database | |
mysql -u root -p Tutorials < tut_backup.sql | |
-- Restore a database that already exists | |
mysqlimport -u [uname] -p[pass] [dbname] [backupfile.sql] | |
-- http://webcheatsheet.com/sql/mysql_backup_restore.php | |
-- http://stackoverflow.com/questions/367711/what-is-the-best-collation-to-use-for-mysql-with-php/25475756#25475756 | |
-- https://mathiasbynens.be/notes/mysql-utf8mb4 | |
-- http://stackoverflow.com/questions/105776/how-do-i-restore-a-dump-file-from-mysqldump# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment