Last active
July 18, 2018 15:17
-
-
Save alexandervantrijffel/ddfe4141b535e4630565b321138c3135 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# allow for remote connections | |
remove bind 127.0.0.1 from /etc/myssql/mysql.conf.d | |
create users as 'myuser'@'%' | |
#setup .mylogin.cnf for auto login | |
mysql_config_editor set --host=localhost --user=lexremote --port=3306 --password | |
#dump database | |
mysqldump DATABASENAME > FILENAME.sql -p | |
#backup all datases to a separate gz file | |
mysql -N -e 'show databases' | while read dbname; do mysqldump --complete-insert --routines --triggers --single-transaction "$dbname" > mysql/mysqldbs/"$dbname".sql; [[ $? -eq 0 ]] && gzip mysql/mysqldbs/"$dbname".sql; done | |
# or | |
mysqldump --databases database_one database_two > two_databases.sql | |
# copy database | |
mysqldbcopy --source=root':YOURPASSWORDHERE'@localhost --destination=root':YOURPASSWORDHERE'@localhost CURRENTDB:NEWDB --drop-first | |
# execute script on DATABASENAME | |
mysql DATABASENAME < mysqlfile.sql | |
SHOW DATABASES; | |
# backup all databases | |
mysqldump --routines --flush-privileges --all-databases --add-drop-database --default-character-set=utf8 > all_mysql_databases.sql | |
#reset root password | |
# echo | |
use mysql; | |
update user set authentication_string=password('YOURPASSWORD') where user='root'; | |
FLUSH PRIVILEGES; | |
# to file /var/lib/mysql/setrootpassword.sql | |
chown mysql:mysql /var/lib/mysql/setrootpassword.sql | |
mysqld_safe --init-file=/var/lib/mysql/setrootpwd.txt & | |
# add admin user with remote accesss | |
CREATE USER 'YOURUSER'@'%' IDENTIFIED BY 'YOURPASSWORD'; | |
GRANT ALL PRIVILEGES ON *.* TO 'YOURUSER'@'%' WITH GRANT OPTION; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment