zeldor.biz

Linux, programming and more

Copyright © 2022
Log in

Migrate MySQL users

December 24, 2020 by Igor Drobot Leave a Comment

Following line will query all mysql user with their grants and print the creation statements for them.

By copy pasting or by filling a SQL-file, you can easily migrate all MySQL-user to a new mysql or mariaDB instance.

mysql -u root -p"YOUR_PW" -Ne "select distinct concat( \"SHOW GRANTS FOR '\",user,\"'@'\",host,\"';\" ) from mysql.user;" mysql | \
mysql -u root -p"YOUR_PW"| \
sed 's/\(GRANT .*\)/\1;/;s/^\(Grants for .*\)/## \1 ##/;/##/{x;p;x;}'

Filed Under: Linux Tagged With: MariaDB, Migrate MySQL User, MySQL, SQL

Categories

Archives

Tags

apache2 Apple arduino ARM Automation backup bash Cisco Cluster Corosync Database Debian Debian squeeze DIY Fedora FTP Fun GIT Icinga Ipv6 KVM Linux LVM MAC OS X Monitoring MySQL Nagios Nginx openSUSE OpenVPN PHP Proxy Python python3 qemu RAID Roundcube rsync security ssh Ubuntu virtualization Windows Windows 7 Wordpress

Leave a Reply

Your email address will not be published. Required fields are marked *