js

Monday, December 16, 2024

Create root user and password in mysql

 

To create a root user and set a password in MySQL, follow the steps below:


1. Access MySQL Server

Log into MySQL as the root user:

sudo mysql -u root

2. Create Root User and Password

In MySQL 8.0, you can create a root user with a secure password and appropriate privileges. Run the following SQL commands:

CREATE USER 'root'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
  • Replace 'your_password' with your desired root password.
  • The @'localhost' means this root user will only be able to connect locally.

3. Allow Root User Remote Access (Optional)

If you want the root user to connect from any remote host (not recommended for production):

CREATE USER 'root'@'%' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
  • '%' allows connections from any IP address.

4. Verify the Root User

To confirm that the root user has been created successfully, list all users:

SELECT User, Host FROM mysql.user;

You should see the root user you created with the appropriate host.


5. Exit MySQL

Exit the MySQL command-line:

EXIT;

6. Test Root User Login

Log in with the newly created root user:

mysql -u root -p
  • Enter the password you set earlier.

Summary of Key Steps:

  1. Log into MySQL as the root user.
  2. Use CREATE USER and GRANT ALL PRIVILEGES to create and configure the root user.
  3. Use FLUSH PRIVILEGES to reload permissions.

Let me know if you encounter any issues! 🚀

No comments:

Post a Comment

Importent softwares to install for Developers after installing UBUNTU

PHP sudo apt install php libapache2-mod-php MYSQL sudo apt install mysql-server Install . deb file in ubuntu sudo dpkg -i package-name.deb