LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General > LinuxQuestions.org Member Success Stories
User Name
Password
LinuxQuestions.org Member Success Stories Just spent four hours configuring your favorite program? Just figured out a Linux problem that has been stumping you for months?
Post your Linux Success Stories here.

Notices


Reply
  Search this Thread
Old 10-08-2018, 08:29 AM   #1
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,685

Rep: Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972
Migrate/copy MySQL (or MariaDB) users from one server to another


While you can easily copy databases using the mysqldump command, and restore them with no problems, often times the user permissions are a problem. You may have created a bunch of users, maybe from different addresses, with different permissions, and moving them over one at a time can be a chore.

So, you can bang these commands into a file, and run it. This *ASSUMES* you have root access (no password) set up, and you're on the MySQL local host where your database is. If you're not, add the appropriate host flag, and specify whatever root-level user you have set up.
Code:
mysql -B -N -e "SELECT CONCAT('\'', user,'\'@\'', host, '\'') FROM user where user!='';" mysql > mysqlusers.txt
while read line; do mysql -B -N -e "SHOW GRANTS FOR $line"; done < mysqlusers.txt > mysql-user-permissions.sql
sed -i 's/$/;/' mysql-user-permissions.sql
This will give you a .sql file, with all your grants/passwords intact. Running this on the new server (again, modify user/host as needed)
Code:
mysql -u root -p < mysql-user-permissions.sql
...imports the file you just created. Done.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Install LEMP Server (nginx, MySQL or MariaDB, PHP) On Ubuntu 13.10 Server LXer Syndicated Linux News 0 10-24-2013 05:40 AM
LXer: Install LAMP Server (Apache, MySQL or MariaDB, PHP) On Ubuntu 13.10 Server LXer Syndicated Linux News 0 10-22-2013 03:50 AM
LXer: Migrate from MySQL to MariaDB in FreeBSD LXer Syndicated Linux News 0 05-19-2013 10:20 AM
[SOLVED] How to migrate linux mysql dump backup to windows mysql server sunrised24 Linux - Server 2 02-14-2012 01:58 PM
migrate / transfer / copy unix users from true 64 to CentOS 5.0 ytd Linux - General 2 01-17-2009 09:27 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General > LinuxQuestions.org Member Success Stories

All times are GMT -5. The time now is 07:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration