DEV Community

Ndirangu Waweru
Ndirangu Waweru

Posted on

1

Create a database and associate it to a user - MySQL

Login to your MySQL root account (or any other account with admin privileges):

mysql -u root -p
Enter fullscreen mode Exit fullscreen mode

Create the database you want your new user to be associated with:

CREATE DATABASE example_database;
Enter fullscreen mode Exit fullscreen mode

Create the new user:

CREATE USER 'example_user'@'localhost' IDENTIFIED BY 'password';
Enter fullscreen mode Exit fullscreen mode

Grant the new user access to the newly created database:

GRANT ALL ON example_database.* TO 'example_user'@'localhost';
Enter fullscreen mode Exit fullscreen mode

Login to MySQL with your new user:

mysql -u example_user -p
Enter fullscreen mode Exit fullscreen mode

Check the databases under the new user:

show databases;
Enter fullscreen mode Exit fullscreen mode

Build something awesome!

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay