Centos7 mysql database installation and configuration tutorial

Centos7 mysql database installation and configuration tutorial

1. System environment

The system version after yum update upgrade is

[root@yl-web yl]# cat /etc/redhat-release
CentOS Linux release 7.1.1503 (Core)

2. MySQL installation

Generally, the information provided on the Internet is

#yum install mysql
#yum install mysql-server
#yum install mysql-devel

The installation of mysql and mysql-devel was successful, but the installation of mysql-server failed, as follows:

[root@yl-web yl]# yum install mysql-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.sina.cn
 * extras: mirrors.sina.cn
 * updates: mirrors.sina.cn
No package mysql-server available.
Error: Nothing to do

After checking the information, I found that the CentOS 7 version removed the MySQL database software from the default program list and replaced it with mariadb.

There are two solutions:

1. Method 1: Install mariadb

MariaDB database management system is a branch of MySQL, mainly maintained by the open source community and licensed under the GPL. One of the reasons for developing this branch is that after Oracle acquired MySQL, there was a potential risk of closing the source of MySQL, so the community adopted the branch method to avoid this risk. MariaDB aims to be fully compatible with MySQL, including API and command line, making it an easy replacement for MySQL.

Install mariadb, size 59 M.

[root@yl-web yl]# yum install mariadb-server mariadb

The relevant commands for the mariadb database are:

systemctl start mariadb #Start MariaDB

systemctl stop mariadb #Stop MariaDB

systemctl restart mariadb #Restart MariaDB

systemctl enable mariadb #Set boot startup

So start the database first

[root@yl-web yl]# systemctl start mariadb

Then you can use mysql normally

[root@yl-web yl]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.41-MariaDB MariaDB Server

Copyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
|mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)

MariaDB [(none)]>

After installing mariadb, MariaDB [(none)]> is also displayed, which may look a bit strange. Here is the second method.

2. Method 2: Download and install mysql-server from the official website

# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
# rpm -ivh mysql-community-release-el7-5.noarch.rpm
# yum install mysql-community-server

After successful installation, restart the mysql service.

# service mysqld restart

When installing MySQL for the first time, the root account has no password.

[root@yl-web yl]# mysql -u root 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.26 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
|mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.01 sec)

mysql>

Set password

mysql> set password for 'root'@'localhost' =password('password'); Query OK, 0 rows affected (0.00 sec)mysql>

No need to restart the database to take effect.

The following are the contents during the MySQL installation process:

Installed:
 mysql-community-client.x86_64 0:5.6.26-2.el7 mysql-community-devel.x86_64 0:5.6.26-2.el7        
 mysql-community-libs.x86_64 0:5.6.26-2.el7 mysql-community-server.x86_64 0:5.6.26-2.el7        

Dependency Installed:
 mysql-community-common.x86_64 0:5.6.26-2.el7                                      

Replaced:
 mariadb.x86_64 1:5.5.41-2.el7_0 mariadb-devel.x86_64 1:5.5.41-2.el7_0 mariadb-libs.x86_64 1:5.5.41-2.el7_0 
 mariadb-server.x86_64 1:5.5.41-2.el7_0

So after installation, mariadb is automatically replaced and will no longer take effect.

[root@yl-web yl]# rpm -qa |grep mariadb[root@yl-web yl]#

3. Configure MySQL

1. Coding

The mysql configuration file is /etc/my.cnf

Finally add the encoding configuration

[mysql]default-character-set =utf8

The character encoding here must be consistent with that in /usr/share/mysql/charsets/Index.xml.

2. Remote connection settings

Assign all permissions on all tables in all databases to the root user at all IP addresses.

mysql> grant all privileges on *.* to root@'%' identified by 'password';

If it is a new user instead of root, you need to create a new user first

mysql>create user 'username'@'%' identified by 'password';

Now you can connect remotely.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Install MySQL5.5 database in CentOS7 environment
  • Detailed tutorial on installing MySQL database in Linux environment
  • Detailed tutorial on installing MySQL 8.0.20 database on CentOS 7
  • How to install MySQL database on Ubuntu
  • Detailed tutorial on installing different (two) versions of MySQL database on Windows
  • Windows Server 2016 MySQL database installation and configuration detailed installation tutorial
  • Install two MySQL5.6.35 databases under win10
  • Introduction to MySQL database installation method and graphical management tool

<<:  Vue implements file upload and download functions

>>:  Detailed example of MySQL subquery

Recommend

Win10 configuration tomcat environment variables tutorial diagram

Before configuration, we need to do the following...

Solution to 404 Problem of Tomcat Installation in Docker

Find the containerID of tomcat and enter the toma...

How to remove spaces or specified characters in a string in Shell

There are many methods on the Internet that, alth...

Pure CSS meteor shower background sample code

GitHub address, you can star it if you like it Pl...

Vue3 (Part 2) Integrating Ant Design Vue

Table of contents 1. Integrate Ant Design Vue 2. ...

What is ssh? How to use? What are the misunderstandings?

Table of contents Preface What is ssh What is ssh...

CSS uses BEM naming convention practice

When you see a class, what information do you wan...

jQuery treeview tree structure application

This article example shares the application code ...

Solution to the CSS height collapse problem

1. High degree of collapse In the document flow, ...

Vue elementUI implements tree structure table and lazy loading

Table of contents 1. Achieve results 2. Backend i...

Talk about the understanding of CSS attribute margin

1.What is margin? Margin is used to control the sp...