Skip to content

Instantly share code, notes, and snippets.

@hgc81538
Last active March 19, 2024 07:13
Show Gist options
  • Save hgc81538/ced674849971790f8d3b to your computer and use it in GitHub Desktop.
Save hgc81538/ced674849971790f8d3b to your computer and use it in GitHub Desktop.
MySQL create database and user in command line
# mysql 8 / mariadb 10.11
mysql -u root
CREATE DATABASE <database_name> CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
CREATE DATABASE <database_name> CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci;
CREATE USER '<username>'@'localhost' IDENTIFIED BY '<password>';
GRANT ALL PRIVILEGES ON <database_name>.* TO '<username>'@'localhost';
flush privileges;
# ref
# https://dba.stackexchange.com/questions/76788/create-a-mysql-database-with-charset-utf-8
# https://www.atlantic.net/dedicated-server-hosting/how-to-create-a-new-user-and-grant-permissions-in-mysql8-on-centos8/
------
mysql -u root -p
create database database_name DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci;
grant all privileges on database_name.* to username@localhost identified by 'password';
flush privileges;
exit;
# create backup user
mysql -u root -p
grant SELECT, SHOW VIEW, RELOAD, REPLICATION CLIENT, EVENT, TRIGGER, LOCK TABLES, PROCESS on *.* to backup@localhost identified by 'password';
flush privileges;
exit;
# ref
# https://www.fromdual.com/privileges-of-mysql-backup-user-for-mysqldump
# https://dba.stackexchange.com/questions/271981/access-denied-you-need-at-least-one-of-the-process-privileges-for-this-ope
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment