Forrest logo
back to the mysql tool

wordpress:database:user:create

Create the user (with permissions) a the WordPress installation
$ mysql -e "CREATE USER '${username}'@'localhost' IDENTIFIED BY '${password}';GRANT ALL PRIVILEGES ON *.* TO '${username}'@'localhost' WITH GRANT OPTION;FLUSH PRIVILEGES;"
try on your machine

This command creates a new MySQL user with the given username and password, and grants all privileges to it on all databases and tables in the MySQL server instance. The command does the following:

  • The "mysql" command runs the MySQL client.
  • The "-e" option tells the client to execute the specified SQL statement, which in this case is a series of SQL statements separated by semicolons.
  • The "CREATE USER" statement creates a new MySQL user with the specified username and password. The "@'localhost'" part specifies that the user can only connect from the same machine where the MySQL server is running.
  • The "GRANT ALL PRIVILEGES" statement grants all privileges to the specified user on all databases and tables in the MySQL server instance. The "WITH GRANT OPTION" part enables the user to grant these same privileges to other users.
  • The "FLUSH PRIVILEGES" statement tells MySQL to reload the user privileges from the grant tables in the MySQL system database. This is necessary to ensure that the newly created user has the necessary privileges to perform database operations.
This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the mysql tool