Create and add a user to a MySQL database using the command line.
Run MySQL
Open MySQL using the below command. The username
should be your root user or an admin user with access for creating other users.
mysql -u username -p
# Enter password when asked
Code language: PHP (php)
Create a database and a user
Create a new database (if required) and create a new user. Grant permissions to the database for the user.
create database dbname;
create user 'dbusername'@'locahost' identified by 'dbpassword';
grant all privileges on dbname.* to 'dbusername'@'locahost';
flush privileges;
Code language: JavaScript (javascript)
Leave a Reply