Related
Hi All, I am trying to configure rapidSVn on Linux (fedora 5). Yum install rapidsvn: On a contemporary Fedora. This is a test with rapidsvn on the long term supported version of Fedora 6 = CentOS 5 / Scientific Linux SL 5. Package wxGTK-devel-2.8.12-1.el5.i386 already installed and latest version.
Managed MySQL, Redis, Postgres on DigitalOcean Product
How To Change Redis's Configuration from the Command Line Tutorial
Introduction
MySQL is an open-source database management system, commonly installed as part of the popular LEMP (Linux, Nginx, MySQL/MariaDB, PHP/Python/Perl) stack. It uses a relational database and SQL (Structured Query Language) to manage its data.
CentOS 7 prefers MariaDB, a fork of MySQL managed by the original MySQL developers and designed as a replacement for MySQL. If you run
yum install mysql
on CentOS 7, it is MariaDB that is installed rather than MySQL. If you’re wondering about MySQL vs. MariaDB, MariaDB will generally work seamlessly in place of MySQL, so unless you have a specific use-case for MySQL, see the How To Install MariaDB on Centos 7 guide.This tutorial will explain how to install MySQL version 5.7 on a CentOS 7 server.
Prerequisites
To follow this tutorial, you will need:
- A CentOS 7 with a non-root user with
sudo
privileges. You can learn more about how to set up a user with these privileges in the Initial Server Setup with CentOS 7 guide.
Step 1 — Installing MySQL
As mentioned in the introduction, the Yum command to install MySQL in fact installs MariaDB. To install MySQL, we’ll need to visit the MySQL community Yum Repository which provides packages for MySQL.
In a web browser, visit:
Note that the prominent Download links don’t lead directly to the files. Instead, they lead to a subsequent page where you’re invited to log in or sign up for an account. If you don’t want to create an account, you can locate the text “No thanks, just start my download”, then right-click and copy the link location, or you can edit the version number in the commands below.
![Centos Centos](/uploads/1/2/5/8/125836461/636945159.jpg)
Locate the desired version, and update it as needed in the link below:
Once the rpm file is saved, we will verify the integrity of the download by running
md5sum
and comparing it with the corresponding MD5 value listed on the site:Compare this output with the appropriate MD5 value on the site:
Now that we’ve verified that the file wasn’t corrupted or changed, we’ll install the package:
This adds two new MySQL yum repositories, and we can now use them to install MySQL server:
Press
y
to confirm that you want to proceed. Since we’ve just added the package, we’ll also be prompted to accept its GPG key. Press y
to download it and complete the install.Step 2 — Starting MySQL
We’ll start the daemon with the following command:
systemctl
doesn’t display the outcome of all service management commands, so to be sure we succeeded, we’ll use the following command:If MySQL has successfully started, the output should contain
Active: active (running)
and the final line should look something like:Note: MySQL is automatically enabled to start at boot when it is installed. You can change that default behavior with
sudo systemctl disable mysqld
During the installation process, a temporary password is generated for the MySQL root user. Locate it in the
mysqld.log
with this command:Make note of the password, which you will need in the next step to secure the installation and where you will be forced to change it. The default password policy requires 12 characters, with at least one uppercase letter, one lowercase letter, one number and one special character.
Step 3 — Configuring MySQL
MySQL includes a security script to change some of the less secure default options for things like remote root logins and sample users.
Use this command to run the security script.
This will prompt you for the default root password. As soon as you enter it, you will be required to change it.
Enter a new 12-character password that contains at least one uppercase letter, one lowercase letter, one number and one special character. Re-enter it when prompted.
You’ll receive feedback on the strength of your new password, and then you’ll be immediately prompted to change it again. Since you just did, you can confidently say
No
:After we decline the prompt to change the password again, we’ll press
Y
and then ENTER
to all the subsequent questions in order to remove anonymous users, disallow remote root login, remove the test database and access to it, and reload the privilege tables.Now that we’ve secured the installation, let’s test it.
Step 4 — Testing MySQL
We can verify our installation and get information about it by connecting with the
mysqladmin
tool, a client that lets you run administrative commands. Use the following command to connect to MySQL as root (-u root
), prompt for a password (-p
), and return the version.You should see output similar to this:
This indicates your installation has been successful.
Conclusion
In this tutorial, we’ve installed and secured MySQL on a CentOS 7 server. To learn more about using MySQL, this guide to learning more about MySQL commands can help. You might also consider implementing some additional security measures.
Install a MariaDB server on CentOS
With the release of CentOS 7, MariaDB replaced MySQL as the default database system. MariaDB was created by the original developers of MySQL, and is an enhanced, drop-in replacement for MySQL with library binary equivalency and exact matching with MySQL APIs and commands.
This article describes a basic installation of a MariaDB database server on CentOS Linux. You might need to install other packages to let applications use MariaDB, such as extensions for PHP. Check your application documentation for details.
Install the database server
Follow the steps in this section to install the core database server.
Install MariaDB
Install the MariaDB server through the CentOS package manager (yum) by running the following command at a command prompt:
Allow remote access
Run the following command to allow remote access:
Set the root password
Because you have just installed the MariaDB database server, the rootaccount has no password set. Use the following command to set the root password and other important settings:
Start and stop the database service
After the installation is complete, you can start the database service by using the commands in this section. If the system is already started, a message informs you that the service is already running.
Use the following command to start MariaDB:
Use the following command to stop MariaDB:
Launch at reboot
To ensure that the database server launches after a reboot, you mustenable the
chkconfig
utility. Use the following command to do this:Start the MariaDB shell
There is more than one way to work with a MariaDB server, but this articlefocuses on the most basic and compatible approach: the
mariadb
shell.- At the command prompt, run the following command to launch the shell and enter it as the root user:
- When you’re prompted for a password, enter the one that you set atinstallation, or if you haven’t set one, press Enter to submit nopassword.The following shell prompt should appear:
View users
MariaDB and MySQL store user information in their own databases. The name of the database is mysql. Inside that database, the user information is in a table, a dataset that is named user. If you want to see what users are set up in the MySQL user table, run the following command:
The following list describes the parts of that command:
- SELECT tells MySQL that you are asking for data.
- User, Host, Password tells MySQL what fields you want it to look in. Fields are categories for the data in a table. In this case, you are looking for the username, the host associated with the username, and the encrypted password entry.
- FROM mysql.user tells MySQL to get the data from the mysql database and the user table.
- A semicolon (;) ends the command.
User hosts
The following example is the output for the preceding query:
Users are associated with a host, specifically the host to which theyconnect. The root user in this example is defined for localhost, for the IP address of localhost, and the hostname of the server. You usually need to set a user for only the host from which you typically connect.
If you’re running your application on the same computer as the MariaDB server, the host that it connects to by default is localhost. Any new users that you create must have localhost in their host field.
If your application connects remotely, the host entry that MariaDB looks for is the IP address or DNS hostname of the remote computer (the one from which the client is coming).
Create a database
There is a difference between a database server and a database,even though those terms are often used interchangeably. MariaDB is adatabase server, meaning that it tracks databases and controlsaccess to them. The database stores the data, and it is the database that applications are trying to access when they interact with MariaDB.
Some applications create a database as part of their setup process, but others require you to create a database and tell the application about it.
To create a database, log in to the
mariadb
shell and run thefollowing command, replacing demodb
with the name of the database that you want to create:The database is created. You can verify its creation by running a query to list all databases. The following example shows the query and example output:
Manage users and privileges
Use the instructions in this section to add users for the database and to grant and revoke privileges.
Add users and privileges
When applications connect to the database using the root user, theyusually have more privileges than they need. You can create a new user that applications can use to connect to the new database. In thefollowing example, a user named demouser is created.
To create a new user, run the following command in the
mariadb
shell:You can verify that the user was created by running a SELECT queryagain:
Grant database user privileges
Right after you create a new user, it has no privileges. The user can be used to log in to MariaDB, but it can’t be used to make any database changes.
- Give the user full privileges for your new database by runningthe following command:
- Flush the privileges to make the change take effect.
- To verify that the privileges were set, run the following command:MariaDB returns the commands needed to reproduce that user’s privileges if you were to rebuild the server.
USAGE on *.*
means that the user gets no privileges on anything by default. That command is overridden by the second command, which is the grant that you ran for the new database.
Revoke privileges
Sometimes you might need to revoke (remove) privileges from a user. For example, suppose that you were granting
ALL
privileges to ‘demouser’@’localhost’, but you accidentally granted privileges to all other databases, too, as shown in the following commands:To correct the mistake, you can use a
REVOKE
statement, followed by GRANT
statement to apply the correct privileges.Now your user has the correct privileges, and your database server is slightly more secure (granting privileges like
ALL on *.*
is deemed as a very bad practice). You should also read official MariaDB documentation regarding possible privilege choices, to grant only those privileges truly needed, rather than using ALL
.Summary
If you’re just creating a database and a user, you are done. Theconcepts covered in this article should give you a solid start from which tolearn more.
Experience what Rackspace has to offer.
©2019 Rackspace US, Inc.
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License