How to create a user and grant privileges in MySQL 8.x using GRANT

Written by - 0 comments

Published on - Listed in MySQL Database Database


Since MySQL 8.x the way MySQL users are created an privileges are granted has changed compared to previous versions.

In previous versions (up to MySQL 5.7), a user could be created at the same time of granting privileges using GRANT in combination with IDENTIFIED BY:

mysql > GRANT ALL ON database.* TO 'sqluser'@'localhost' IDENTIFIED BY 'secret';

Since MySQL 8.x, this doesn't work anymore and an error message appears:

mysql > GRANT ALL ON database.* TO 'sqluser'@'localhost' IDENTIFIED BY 'secret';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IDENTIFIED BY 'secret'' at line 1

In this case, the user must be created first (using CREATE USER) and then the privileges must be assigned to the existing user:

mysql > CREATE USER 'sqluser'@'localhost' IDENTIFIED BY 'secret';
mysql > GRANT ALL ON database.* TO 'sqluser'@'localhost';



Add a comment

Show form to leave a comment

Comments (newest first)

No comments yet.

RSS feed

Blog Tags:

  AWS   Android   Ansible   Apache   Apple   Atlassian   BSD   Backup   Bash   Bluecoat   CMS   Chef   Cloud   Coding   Consul   Containers   CouchDB   DB   DNS   Database   Databases   Docker   ELK   Elasticsearch   Filebeat   FreeBSD   Galera   Git   GlusterFS   Grafana   Graphics   HAProxy   HTML   Hacks   Hardware   Icinga   Icingaweb   Icingaweb2   Influx   Internet   Java   KVM   Kibana   Kodi   Kubernetes   LVM   LXC   Linux   Logstash   Mac   Macintosh   Mail   MariaDB   Minio   MongoDB   Monitoring   Multimedia   MySQL   NFS   Nagios   Network   Nginx   OSSEC   OTRS   Office   PGSQL   PHP   Perl   Personal   PostgreSQL   Postgres   PowerDNS   Proxmox   Proxy   Python   Rancher   Rant   Redis   Roundcube   SSL   Samba   Seafile   Security   Shell   SmartOS   Solaris   Surveillance   Systemd   TLS   Tomcat   Ubuntu   Unix   VMWare   VMware   Varnish   Virtualization   Windows   Wireless   Wordpress   Wyse   ZFS   Zoneminder   


Update cookies preferences