Example: Resetting the WordPress Admin password Make sure to change your directory to /root or /home or another location in your file system that requires proper credentials. We recommend that you run this command from a directory that is not publicly accessible so that your database cannot be downloaded from your account without logging into the command line or FTP. This will allow you to restore MySQL Databases Using mysqldump from this backup file at any time.
sql as the type of file to save your database. Replace the database name with your actual database name and database backup with the name of the file you would like to create and end it with. mysqldump database name > databasebackup.sql Use mysqldump to make a backup of your database before continuing with this guide is strongly recommended. The 'show ' command is also used to list the tables in a database: MariaDB > show tables Īlways Take a Backup Before Making ANY Changes Switch Database With The 'use ' command: MariaDB > use tutorials An example is shown below: MariaDB > show databases Issue the show databases command, as seen below, to see all databases. Once you run a the command below and enter your password, you will be presented with a prompt that tells you the program really running (MariaDB) and the database is used: mysql -u root -p (Other systemd-based Linux distros may have similar commands depending on whether they run actual MySQL or MariaDB other init systems will be different)
Plaintext use mysql update user set password=PASSWORD("InsertPasswordHere") where User='root' where 'InsertPasswordHere' is a real password flush privileges exit systemctl stop mariadb Mysqld_safe -skip-grant-tables -skip-networking & To log in to the database as the root user, use the following command: mysql -u root -pĮnter the root password. Common MySQL Tasks Done Through Command Line Login To MySQL Database prompts indicate something that should be entered from the Bash command line, > prompts are inside MySQL itself.
This page assumes you have Connected to Your Server with SSH. The examples in this guide are for CentOS 7 and MariaDB as included in our WordPress VPS image but should work on our cPanel VPSes, LAMP stack, and others.
This article will touch on getting into a database and some common tasks but will not provide a full education on SQL syntax, database management, or other high-level topics. While tools like phpMyAdmin interact with MySQL / MariaDB databases very easily, sometimes one must access the database directly from the command line.