CentOS 7 installs mysql to change data storage location

Keywords: MySQL yum Database Oracle

Recently, I changed my computer system to centos. Everyday development tools need to be reconfigured. Here I record the configuration of mysql, which is different from the ubuntu series.

Reference resources: http://www.centoscn.com/mysql/2016/0315/6844.html
1. MySQL relies on libaio, so first install libaio

yum search libaio  # Retrieval of relevant information
yum install libaio # Install dependency packages
  1. Check that MySQL is installed
yum list installed | grep mysql
If so, uninstall them one by one

3. Download MySQL Yum Repository

wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm

Add MySQL Yum Repository to your system repository list

yum localinstall mysql-community-release-el7-5.noarch.rpm

Verify whether the addition is successful:

yum repolist enabled | grep "mysql.*-community.*"

You can see the following

[root@bogon software]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64        MySQL Connectors Community           1
mysql-tools-community/x86_64             MySQL Tools Community                1
mysql56-community/x86_64                 MySQL 5.6 Community Server          13
  1. Installing Mysql through Yum
yum install mysql-community-server
  1. Test for successful installation
mysql

Seeing this makes it possible.

[root@bogon software]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.24 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>
  1. At this time, mysql has no password, and it feels so different from ubuntu.
mysql_secure_installation;
[root@bogon software]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):

Hit you to change your password, start empty, enter directly. Next, MySQL will prompt you to reset the root password, remove other user accounts, disable root remote login, remove the test database, reload the privilege form, etc. You just need to enter y to continue execution.

So far, the entire installation of MySQL is complete, you can use the mysql-u root-p command.

Now let's start modifying the database location:
Here I am fooled, centos management is more stringent, your new database address can not be in a user directory, such as: / home/miclewang813/mysql, so even if your later configuration is completely correct, the restart service can not run. It's better to use / home/mysql, so that your data location does not depend on the user directory and is more secure.

service mysql stop           #Stop database services
cp -r /var/lib/mysql /home   #Copy mysql database storage file to / home directory (new address)
chown -r mysql:mysql /home/mysql  #Change the permissions for the new database location to mysql
mv /var/lib/mysql/mysql.sock /var/lib/mysql/back.sock
                                  #Back up the original sock file
ln -s /home/mysql/mysql.sock    /var/lib/mysql/mysql.sock
                                  #Link mysql.sock to its original location
vim /etc/my.cnf                  #Modify configuration
#Old address
#datadir=/var/lib/mysql
#socket=/var/lib/mysql/mysql.sock
#new address
datadir=/home/mysql
socket=/home/mysql/mysql.sock

Then: restart the service mysql restart.

Posted by Willburt on Sat, 22 Jun 2019 14:29:33 -0700