Change the Root Password of MySQL or MariaDB in Linux

Summary: If you are installing MySQL or MariaDB for the first time, you can execute the mysql_secure_installation script to implement basic security settings. One of these settings is the root password for the database -- this password must be kept secret and used only when necessary.

If you are installing MySQL or MariaDB for the first time, you can execute the mysql_secure_installation script to implement basic security settings.

One of these settings is the root password for the database -- this password must be kept secret and used only when necessary. If you need to modify it (for example, when the DBA changes people -- or gets fired!).

Suggested Read: Recover MySQL or MariaDB Root Password in Linux

This article will come in handy sooner or later. We explain how to change the root password of a MySQL or MariaDB database server in Linux.

Although we will use the MariaDB server in this article, the usage instructions in this article are also valid for MySQL.

Change the root password for MySQL or MariaDB
You root password, but want to reset it, for this case, let's first make sure MariaDB is running:

------------- CentOS/RHEL 7 and Fedora 22+ -------------
# systemctl is-active mariadb
------------- CentOS/RHEL 6 and Fedora --------- ----
# /etc/init.d/mysqld status
Check MysQL Status
Check MysQL Status

If there is no active keyword in the return of the above command, then the service is in a stopped state, and you need to start the database service before proceeding to the next step:

------------- CentOS/RHEL 7 and Fedora 22+ -------------
# systemctl start mariadb
------------- CentOS/RHEL 6 and Fedora ------ -------
# /etc/init.d/mysqld start
Next, we will log into the database server as root:

# mysql -u root -p
For compatibility with different versions, we will update mysql with the following statement The user table of the database. Note that you need to replace YourPasswordHere with the new password you chose for root.

MariaDB [(none)]> USE mysql;
MariaDB [(none)]> UPDATE user SET password=PASSWORD('YourPasswordHere') WHERE User='root' AND Host = 'localhost';
MariaDB [(none)]> FLUSH PRIVILEGES ;
To verify that the operation was successful, exit the current MariaDB session by entering the following command.

MariaDB [(none)]> exit;
Then, hit enter. You should now be able to connect to the server with the new password.

Change MysQL/MariaDB Root Password
Change MysQL/MariaDB Root Password

Summary
In this article, we explained how to change the root password of MariaDB / MySQL -- maybe you know this method so far, or you may not.

The original release time is: 2017-03-22

This article is from the Yunqi community partner "Linux China"


using the Yunqi community APP, comfortable ~

[Yunqi Express] Quickly solve database problems, cloud database classic cases and best practices live broadcast! Alibaba Cloud database expert team members teach each other! Sign up now. For details, please click
Comments (0) (0) (0) Share to:
Related Articles

How to reset MySQL or Maria in Linux… CentOS mysql installation and use How to configure MariaDB in CentOS Linux… on Ubuntu 14.10/14.04/13.10 … MariaDB ColumnStore Preliminary Exploration (1): Installation, … Quickly install lamp on Linux system Install your personal cloud service in Linux using ownCloud Install and configure PowerDNS in RHEL/CentOS 7… Install in RHEL/CentOS 7 And configure PowerDNS...
Netizen Comments You can comment after

logging in, please log in or register
Comments
Follow
Light Color Love つ
1043 articles|4
Follow Cloud products mentioned in the article
Data management
Supports relational databases and NoSQL such as MySQL, SQL Server, PostgreSQL, MongoDB, Redis...
Learn more
Encryption service
The bottom layer of the service uses a hardware encryption machine that has been tested and certified by the State Cryptography Administration. Regulatory compliance requirements for data security, cloud protection... Learn
more ApsaraDB for RDS RDS is a stable, reliable, and elastically scalable online database service. Support MySQL, SQL Server, PostgreSQL, high... Learn more Cloud Server ECS provides you with simple and efficient computing services with elastically scalable processing capabilities, helping you quickly build more stable and secure applications, improve operation and maintenance efficiency, reduce IT Costs... Learn More Contents Collapse 1 Modify MySQL or MariaDB Root Password 2 Summary Bloggers Other Articles More > Using the New apt Command to Manage Packages under Ubuntu 16.04 LTS Create Your Own Arch with arch-ppa Linux Repositories Backup/Restore Your Ubuntu/Linux Mint with SystemBack Extend Partition Size with fdisk under Linux How to Install Plesk on Virtuozzo The Ultimate Guide to Creating and Publishing Android Development Libraries
















Linux Kernel Self-Defense Project KSPP
LFCS Series Lecture 8: Managing Users and User Groups, File Permissions and Attributes, and Enabling Account Sudo Access
ZFS That Thing
How to Use the VIM File Management Plugin NERDTree Elegantly

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326222333&siteId=291194637