Resetting Your MYSQL Root Password

  1. The first step to resetting your root MySQL password on a Linux server is to stop MySQL. If you have a monitoring service for MySQL that will restart the service if it is down, make sure that service is also stopped for the time being, such as checkservd and cPanel.
    /etc/init.d/mysql stop
  2. Next, start MySQL in Single User Mode and enter without a password.

    Warning:

    Restarting MySQL this way will allow anyone access to every database. To avoid this, stop eth0 and fuser -k any logged in user and touch /etc/nologin.
    mysqld_safe --skip-grant-tables & mysql

    Note:

    Make sure to add & or the command prompt will not show.
  3. Enter the following commands in the MySQL prompt. The password below is only an example, replace 123456ABCDEF with the password of your choice. Our article Best Practice: Creating a Secure Password provides you with information on secure password best practices.
    UPDATE mysql.user SET password=password("123456ABCDEF") 
    WHERE user='root';
    FLUSH PRIVILEGES;
    exit;
  4. Stop MySQL safe and start MySQL and all other services that kept it from restarting like checkservd and cPanel normally.
    /etc/init.d/mysql stop
    /ect/init.d/mysql start
  5. Test your change by doing a test login, to log into MySQL, type it into the command line.
    mysql
  6. You will be prompted to enter your password. Enter the new password, if you are logged in then you have successfully reset the MySQL root password.

Note:

If the MySQL user has been deleted, run the following query to recreate it:

INSERT INTO `mysql`.`user` ( `Host` , `User` , `Password`
 , `Select_priv` ,`Insert_priv` , `Update_priv` ,`Delete_priv` 
 , `Create_priv` , `Drop_priv` , `Reload_priv` , `Shutdown_priv` 
 , `Process_priv` , `File_priv` , `Grant_priv` , `References_priv` 
 , `Index_priv` , `Alter_priv` , `Show_db_priv` , `Super_priv` 
 ,`Create_tmp_table_priv` , `Lock_tables_priv` , `Execute_priv` 
 , `Repl_slave_priv`, `Repl_client_priv` , `Create_view_priv` 
 , `Show_view_priv` , `Create_routine_priv` , `Alter_routine_priv` 
 , `Create_user_priv` , `max_questions` , `max_updates`
 , `max_connections` , `max_user_connections` ) VALUES ( 'localhost'
 , 'root',PASSWORD('password1234'), 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y'
 , 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y','Y', 'Y', 'Y', 'Y'
 , 'Y', 'Y', 'Y', 'Y', 'Y', '0', '0', '0', '0' );

Troubleshooting

You may encounter an error when trying to change the root password that looks like the example below:

mysql> show warnings; +---------+------+-----------------------------------------------+ 
| Level | Code | Message | +---------+------+-----------------------------------------------+ 
| Warning | 1265 | Data truncated for column 'Password' at row 1 | 
| Warning | 1265 | Data truncated for column 'Password' at row 2 | 
+---------+------+-----------------------------------------------+

 

If MySQL is giving you warnings when changing the password, type the following:
mysql>prompt

 

Then leave MySQL and run:

/usr/bin/mysql_fix_privilege_tables

Once this is complete, try to set the password again. If you have further issues, please contact our Support team and we will be happy to assist you!

How To Install the LAMP Stack on CentOS 7

Pre-flight Checks

To find out which Linux distribution you are running, use this command:
cat /etc/redhat-release
It’s now time to verify that our yum environment is clean and up to date, we’ll do this by cleaning all of the yum cache, and update yum using:
yum clean all
yum update

Installing LAMP

Now that we know what environment we’re working in let’s get started on installing the LAMP stack on CentOS 7:

L – Linux

The first part of the stack is Linux. This is your operating system and since it is already installed there no need to worry about installing it or make any modifications. Installing CentOS 7 is easy to download and install using the image files that are provided from centos.org. CentOS has a helpful installation guide if you need to reference it for additional installation instructions.

A – Apache

Apache is the next piece of the LAMP stack. Apache is the webserver software that is responsible for serving the content to your web browser from the server. It takes the requests that it receives and sends back the HTML code for your browser to interpret.
Install Apache using Yum:
yum -y install httpd

Open ports in the FW:
firewall-cmd --permanent --add-service=http -add-service=https
firewall-cmd --reload

Start and enable apache to run when the server starts:
systemctl start httpd
systemctl enable httpd

Default Apache installation locations:

Some important server locations to remember for Apache are listed below. These are out-of-the-box defaults and can be changed as you see fit:
httpd binary: /sbin/httpd
Apache configuration file: /etc/httpd/conf/httpd.conf
Website files: /var/www/html/
Apache logs: /var/log/httpd/

M – MySQL/MariaDB

MySQL and MariaDB are what handle your website’s database. In most of today’s websites, data is not stored in flat or static files. Instead, the base of the site is coded in PHP which can pull information from your website’s database to deliver more dynamic content. MySQL and MariaDB are popular database servers that help house that information. MariaDB is becoming more widely used, so we’ll use for installation. Both are very similar in setting up and configuring.

Install MariaDB:
yum -y install mariadb-server
systemctl start mariadb

Although securing mysql is optional, it is strongly recommended:
mysql_secure_installation
**Run through the steps on screen to secure your Mysql/MariaDB environment

Enable MariaDB to start when the server starts:
systemctl enable mariadb

Default installation locations:

Some important server locations to remember for MySQL/MariaDB are listed below. These are out-of-the-box defaults and can be changed as you see fit:
MariaDB binary: /bin/mysql
MariaDB Configuration file: /etc/my.cnf
Database location: /var/lib/mysql
MariaDB logs: /var/log/mariadb/mariadb.log

P – PHP

Most websites that exist today are built using PHP coding. PHP provides the programmer with more options for dynamic content compared to flat html code. Several PHP versions are available for use depending on what PHP version the website was built in. We’ll install the latest version of PHP.

In order to install the latest PHP version, we first need to install CentOS’s Software Collection repository (SCL):
yum -y install centos-release-scl.noarch

We’ll now have access to install PHP 7.2 :
yum -y install rh-php72

Now we’ll fix the symbolic link for the binary:
ln -s /opt/rh/rh-php72/root/usr/bin/php /usr/bin/php

Install the updated PHP Module for Mysql/MariaDB:
yum -y install rh-php72-php-mysqlnd

Restart apache to work with the newly installed PHP:
systemctl restart httpd

How To Install PHP 7, 7.2 & 7.3 On CentOS 7

Prerequisites

How to Install PHP 7.2 with Apache on CentOS

Step 1: Choose PHP Version to Install

The newest stable release version of PHP is PHP 7.3.1. However, some software repositories default to older versions of the software.

One advantage of using an older release is its high stability and reliability. Newer releases may include more features, but are often more experimental and could cause system instability. If you cannot decide which version is right for you, version 7.2 is a great place to start.

Step 2: Enable Additional Software Repositories

By default, the yum package manager does not include access to the repositories that store the PHP packages. Therefore, you need to enable access to these software packages.

1. First, start by installing the yum-utils package by entering the following command in a terminal window:

sudo yum install yum-utils –y

2. Then, enable the epel-release repository by entering the following:

sudo yum install epel-release –y

3. Finally, add the following software repositories that contain the PHP packages:

sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

Step 3: Enable Repository For PHP Version

Next, use the yum-config-manager to point your installer to the repository of the PHP version you want to install:

sudo yum-config-manager ––enable remi–php70

This command configures your system to download and install PHP 7.0.
To install PHP 7.1, change the entry as follows:

sudo yum-config-manager ––enable remi–php71

Likewise, replace the last two characters with 72 to install PHP 7.2.

 

Step 4: Install PHP and its Dependencies

At this point, you can install PHP. Enter the following command in the terminal:

sudo yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysql –y

As you see, the line includes many of the modules and add-ons that help PHP integrate with your local server configuration.

The output will also indicate which dependencies have been installed.

 

Step 5: PHP Modules

You may have noticed that the installation script included more than just the base PHP package. Many of these are modules that provide basic functionality to PHP. Installing this set helps ensure that your PHP installation meets your expectations for usage.

Like many other Linux applications, you can enhance your system’s PHP functionality using modules.

To search for available modules and generate a list of modules, type in the following command:

sudo yum search php | more

Step 6: Verify PHP Version

Finally, verify your installation was successful. Check which version of PHP you are running with the command:

php –v

Optional: Install PHP 7.3

You can enable Remi’s PHP 7.3 repository the same way you enabled other repositories in Step 3. However, this installation may fail if you have extensions that are not compatible with PHP 7.3.

If this is a first-time installation and you are confident that your system is compatible, you can enable PHP 7.3. Install the release with the following commands:

sudo yum-config-manager ––enable remi–php73
sudo yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysql –y

How To Install MySQL on CentOS 7

Prerequisites

Guide To Installing MySQL on CentOS 7

Step 1: Download Repository Packages

Open a browser window, and go to the following address:

https://dev.mysql.com/downloads/repo/yum/

This page lists MySQL setup packages in the Yum repository.

 

Find the Red Hat Enterprise Linux version that you want to download. (At the time of writing, the website offers Linux 8, Linux 7 and Linux 6.)

 

You can click the Download button, which takes you to a registration page. You can sign up if you’d like or select the No thanks, just start my download link.

 

Download MySQL with wget Command

Alternately, you can open a terminal and use the wget command to save the file. On the web page that lists release versions, you’ll see a gray subtext that shows something like “(mysql80-community-release-el7-1.noarch.rpm)”. That’s the setup package of a specific package.

Copy the name of the desired setup package, then open a terminal window and enter the following command:

sudo wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

The system should reach out and download the files. Make sure you check the website and copy the exact release ID – use that in your terminal command.

Leave the browser window open for the next step.

Step 2: Add the Software Repositories

The files we just downloaded provide access to the MySQL software repositories. Before adding them, use the md5sum command to authenticate the software:

sudo md5sum mysql80-community-release-el7-3.noarch.rpm

The system should respond with a long string of letters and numbers.

Switch back to the MySQL web page and look just below the Download link to find a gray string of numbers labeled MD5.

Compare the MD5 value on the web page to the MD5 value you generated in the terminal window. If they match, proceed to the next step.

If they don’t match, it’s possible that your download was corrupted in transit. Or, it’s possible that the download has been compromised. Repeat Steps 1 and 2 and overwrite the downloaded file. If the MD5 values still don’t match, stop the procedure.

To update the software repositories, use the command:

sudo rpm –ivh mysql80-community-release-el7-3.noarch.rpm

Make sure you’ve entered the release version from Step 1. This will add 2 new Yum repositories that we can get MySQL from.

Step 3: Install MySQL

Install MySQL on CentOS by entering the following:

sudo yum install mysql-server

The system will ask for confirmation, press Y to confirm.

It should also request that you accept a GPG (Gnu Privacy Guard) key. This is another security confirmation because we just added two new software sources. Press Y again, and the system should download and install the software.

Using MySQL

Managing MySQL Service

You’ll need to start the MySQL service by entering:

sudo systemctl start mysqld

To check the status of MySQL use the command:

sudo systemctl status mysqld

The system will display several lines of information about the MySQL service. In the Active line, it should display active: (running). You may also see a line below that shows a timestamp of when the service was started.

By default, the MySQL service is set to launch at startup.

To disable it, you can use the disable command:

sudo systemctl disable mysqld

To stop the MySQL service, use the stop command:

sudo systemctl stop mysqld

Find Temporary Password

The MySQL installation routine sets up a default temporary password.

Use the grep command to find the password:

sudo grep ‘temporary password’ /var/log/mysqld.log

Make a note of the password.

Configuring and Securing

Your new MySQL installation comes with a security script to make securing configurations easier.

Launch the script with the following terminal command:

sudo mysql_secure_installation

The system will prompt you to enter the default root password. Enter the password you recovered earlier.

Next, the system will tell you that the password has expired, and prompt you to enter a new one. Enter a new password, make a note of it, then press Enter.

The system will rate your password strength, and ask if you want to enter a new, stronger password. If you’re satisfied with your password strength, hit the spacebar. To revise your password, press Y.

The Secure Installation script will continue, and you can safely reply Y to the rest of the prompts, which include:

  • Remove anonymous users
  • Disallow remote root login
  • Remove test database
  • Reload privilege tables

Log into MySQL

To launch MySQL from the command line, use the command:

mysql –u root –p

The system will prompt you to enter your password. Enter the password you set in Step 6, and the system should respond by displaying the MySQL shell.

It lists necessary information about the MySQL software, and your command prompt will change to mysql> to indicate that you’re logged into the MySQL software.

Once you’re done, you can log out with:

exit

The command prompt will change, indicating that you’ve logged out of MySQL.