User Tools

Site Tools


bash:mysql_migrate_server

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
bash:mysql_migrate_server [2013/09/10 18:33] – created biggibash:mysql_migrate_server [2015/08/15 22:56] (current) – external edit 127.0.0.1
Line 5: Line 5:
 If you use it and make any changes, please send them to me (Biggi@Biggi.dk). Unfortunately comments and users are disallowed due to those retarded spam-bots always trying to rake in cash on every website, and I'm not about to spend an hour cleaning up this wiki once a week. If you use it and make any changes, please send them to me (Biggi@Biggi.dk). Unfortunately comments and users are disallowed due to those retarded spam-bots always trying to rake in cash on every website, and I'm not about to spend an hour cleaning up this wiki once a week.
  
-<code - movesql.sh>+<file bash movesql.sh>
 #!/bin/bash #!/bin/bash
 # TODO: # TODO:
 # Write warning: sshpass 1.04 does not work. 1.05 required :/ # Write warning: sshpass 1.04 does not work. 1.05 required :/
 # Add option to use another port than 3306 and 22 # Add option to use another port than 3306 and 22
 +# DONE:
 +# 2013-12-17 - Ignoring 'debian-sys-maint'-user when dumping privileges
 +# 2013-12-17 - Flushing privileges at the end (to make sure new mysql permissions + passwords work)
  
 # Verify sshpass + mysqldump + pigz # Verify sshpass + mysqldump + pigz
Line 66: Line 69:
 read -s dstsqlrootpwd read -s dstsqlrootpwd
  
-echo " Enter the destination username (you will be queried about the password when it's needed)"+echo " Enter the destination ssh username"
 read dstuser read dstuser
  
-echo " Enter the destination password (chars will not be shown in the terminal)"+echo " Enter the destination ssh password (chars will not be shown in the terminal)"
 read -s dstpass read -s dstpass
  
Line 141: Line 144:
  
 # Grab user data # Grab user data
-for x in `mysql -u root --password=$sqlrootpwd -B -N -e"select user, host from user" mysql`; do+for x in `mysql -u root --password=$sqlrootpwd -B -N -e"SELECT user, host FROM user WHERE user != 'debian-sys-maint'" mysql`; do
  UNAME=`echo $x | awk {'print $1'}`;  UNAME=`echo $x | awk {'print $1'}`;
  UHOST=`echo $x | awk {'print $2'}`;  UHOST=`echo $x | awk {'print $2'}`;
Line 190: Line 193:
  
 echo "* Importing sql user data on remote system"; echo "* Importing sql user data on remote system";
-IMPORPRIVILEGES=`sshpass -p "$dstpass" ssh -o StrictHostKeyChecking=no $dstuser@$dstip "mysql -N -s -u root --password=\"$dstsqlrootpwd\" -e\"$ALLPRIVILEGES\" " 2>&1`+IMPORTPRIVILEGES=`sshpass -p "$dstpass" ssh -o StrictHostKeyChecking=no $dstuser@$dstip "mysql -N -s -u root --password=\"$dstsqlrootpwd\" -e\"$ALLPRIVILEGES\" " 2>&1` 
 + 
 +echo "* Flushing privileges on remote system"; 
 +FLUSHPRIVILEGES=`sshpass -p "$dstpass" ssh -o StrictHostKeyChecking=no $dstuser@$dstip "mysql -N -s -u root --password=\"$dstsqlrootpwd\" -e\"FLUSH PRIVILEGES;\" " 2>&1`
  
 echo " ----------------------------"; echo " ----------------------------";
Line 196: Line 202:
 echo " ----------------------------"; echo " ----------------------------";
  
-</code>+</file>
bash/mysql_migrate_server.1378830836.txt.gz · Last modified: 2015/08/15 22:56 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki