Skip to content

Instantly share code, notes, and snippets.

@jasperf
Last active September 7, 2024 10:15
Show Gist options
  • Save jasperf/2a82c0edb102698c60d0 to your computer and use it in GitHub Desktop.
Save jasperf/2a82c0edb102698c60d0 to your computer and use it in GitHub Desktop.
Homebrew Create a MySQL database and user to be used for a WordPress site from the command line with mysql and restart server when you have a socket error or other error #wordpress #mysql #homebrew
//homebrew mysql start
/usr/local/Cellar/mysql/5.6.19/bin/mysql.server restart
//or
mysql.server start
//check for access privileges
mysqlaccess localhost user database
//http://codex.wordpress.org/Installing_WordPress#Using_the_MySQL_Client
$ mysql -u adminusername -p
//Homebrew installed mysql does not require password for root
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5340 to server version: 3.23.54
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> CREATE DATABASE databasename;
Query OK, 1 row affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON databasename.* TO "wordpressusername"@"hostname" IDENTIFIED BY "password";
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
mysql> EXIT
Bye
$
@Alsy
Copy link

Alsy commented Apr 16, 2019

With the latest version of mysql it looks like you need to first create the user and then do a "grant all".

i.e.:
create user "wordpressusername"@"hostname" identified by "password";
grant all privileges on databasename.* to "wordpressusername"@"hostname";

@danielortiz
Copy link

for some reason wordpress wouldn't connect to it.
This solved it though
ALTER USER 'username'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
https://stackoverflow.com/questions/50037975/wordpress-cannot-connect-to-mysql-server

@ericel
Copy link

ericel commented Aug 23, 2022

very helpful

@prayogarm
Copy link

when i create new database, i got an error, some body help me?

ERROR 1006 (HY000): Can't create database 'laravel' (errno: 2 "No such file or directory")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment