Changing MySQL root password on Mac
This article teaches you how to change the MySQL user password on OS X. root
We will be using XAMPP so that you can change the password using the MySQL console.
Installing XAMPP for OSX
First, download and install XAMPP for OSX from Apache Friends. After installing XAMPP, use the terminal to access the XAMPP installation directory.
Afterwards, log into MySQL using the following command:
mysql -u root -p
As it stands, root
the user has no password. As a result, the preceding command will log into MySQL without a password prompt.
But before we change the password, let's make sure root
there is no password.
Confirm root
User has no password
To confirm that root
the user has no password, switch to mysql
the database with the following command:
USE mysql;
mysql
The database has many tables, but the one we are interested in is user
the table. user
A table has User
and Password
columns.
The latter contains the user's password. Therefore, check the user's password with the following command root
:
SELECT User, authentication_string from user;
Output (if root
no password):
+------------------+------------------------------------------------------------------------+
| User | authentication_string |
+------------------+------------------------------------------------------------------------+
| debian-sys-maint | $A$005$Wv1MO|Uh1gezb+wKL5oU1hvgAp90tnMa9fTMbPNZtGAFSYC6dgziVVPAd0 |
| mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| root | |
| temp | $A$005$)e>qXOK0S_d
l(JVnBtaCRN8F8OFHnnWVFxXGM1kRPHMq/1kNQvGZQRiR5 |
+------------------+------------------------------------------------------------------------+
6 rows in set (0.01 sec)
If the root user does not have a password, your output should be the same as above. Now, let's change the password.
Use SQL ALTER
statements to change root
user passwords
To change root
a user's password, you will use a SQL ALTER
statement to assign a new password. Therefore, the following will root
change the password to DelftStack
:
ALTER USER root@localhost IDENTIFIED BY 'DelftStack'
Output:
Query OK, 0 rows affected (0.021 sec)
Now, confirm that root
you have the password:
SELECT User, authentication_string from user;
Output (your code will be different):
+------+-------------------------------------------+
| User | Password |
+------+-------------------------------------------+
| root | *D064C3894639CE84CBA931173B3A55263B736A7B |
| root | |
| root | |
| pma | |
+------+-------------------------------------------+
4 rows in set (0.001 sec)
To ensure that the password change takes effect the next time you log in, refresh the permissions:
FLUSH PRIVILEGES;
Log in with your new root
user password
root
Once the user has a password, you can log in with:
mysql -u root -p
After executing the previous command, MySQL will ask you to enter your password. If you enter the correct password, you will be logged in; otherwise, you will receive 拒绝访问
a message. If this happens, double-check your password and try again.
For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.
Related Articles
Using CURRENT_TIMESTAMP as a default value in MySQL
Publish Date:2025/04/21 Views:196 Category:MySQL
-
This article teaches you how to use as 5.6.5 in MySQL versions lower than . Thus, you can prevent MySQL error 1293. CURRENT_TIMESTAMP DEFAULT Our approach involves reordering table columns and using DEFAULT 0 and time values. Reproduce the
If ELSE in MySQL
Publish Date:2025/04/11 Views:86 Category:MySQL
-
In this tutorial, we aim to explore how to use IF ELSE the statement in MySQL. One of the key roles of a data analyst is to gather insights from the data and produce meaningful results. It can be done with the help of several data filtering
DATETIME vs. TIMESTAMP in MySQL
Publish Date:2025/04/11 Views:117 Category:MySQL
-
DATETIME and TIMESTAMP are two different data types that can be used to store values that must contain both a date and a time portion. In this article, we will understand how it is stored in the database and the memory required for ea
Execute multiple joins in one query in MYSQL
Publish Date:2025/04/11 Views:94 Category:MySQL
-
Have you ever wondered how to include multiple joins in one query in MySQL? You have come to the right place. Remember that joins allow us to access information from other tables. This information is included separately to avoid redundancy.
Joining 3 tables in MySQL
Publish Date:2025/04/11 Views:187 Category:MySQL
-
In this tutorial, we will learn how to join three tables in MySQL. Businesses and organizations may have to visualize three tables simultaneously based on certain matching columns common to all three tables. This operation is allowed in MyS
Use of UPDATE JOIN in MySQL
Publish Date:2025/04/11 Views:85 Category:MySQL
-
This tutorial will explain how to use the statement in MySQL database UPDATE JOIN . We generally use joins to iterate over the rows in a particular table which may or may not have similar rows in other tables. We can UPDATE use JOIN the cla
How to use the Row_Number() function in MySQL
Publish Date:2025/04/11 Views:143 Category:MySQL
-
In this tutorial, we will explain how to use the VALUES function in MySQL ROW_NUMBER() . This is a sorting method that assigns consecutive numbers within a partition starting from 1. It is important to note that no two rows within a partiti
Multiple primary keys in MySQL
Publish Date:2025/04/11 Views:66 Category:MySQL
-
In this tutorial, our goal is to explore the concept of multiple primary keys for a table in MySQL. Many times, businesses and organizations have to assign certain columns as primary keys. This primary key has multiple uses and reasons to b
Displaying foreign keys in MySQL
Publish Date:2025/04/11 Views:55 Category:MySQL
-
In this tutorial, we aim to explore how to display foreign keys for tables and columns in MySQL. The type of key that references a primary key, also known as the primary key of another table, is called a foreign key. Understanding the forei