How to install MySQL 5.7 on Ubuntu and configure the data storage path

How to install MySQL 5.7 on Ubuntu and configure the data storage path

1. Install MySQL

This article is installed via APT, and the latest version installed is 5.7.21

(Note: The versions installed via APT are the latest versions. After installation in this way, the startup and environment variables on the command line are already configured, and no manual configuration is required.)

sudo apt-get install mysql-server

If insufficient dependencies are prompted, run the following command to resolve the dependency problem. If no dependency problem occurs, then you do not need to use this command

sudo apt-get install -f

During the installation process, you will be prompted to enter the root user password twice.

Note: After installation in this way, the startup and automatic startup are already configured, and the environment variables on the command line do not need to be configured manually.

After installation, the following directories will be created:

Database directory: /var/lib/mysql/

Configuration files: /usr/share/mysql (command and configuration files), /etc/mysql (such as: my.cnf)

Related commands: /usr/bin (mysqladmin mysqldump and other commands) and /usr/sbin

Startup script: /etc/init.d/mysql (directory of the startup script file mysql)

Service management startup sudo service mysql start
Stopsudo service mysql stop
Service status sudo service mysql status

2. Configure MySQL data storage path

I use Alibaba Cloud, which provides me with a 20G data disk. The path after mounting is /data.

Create a folder

mkdir /data/mysql

Copy the default installed MySql database to /data/mysql and set permissions

sudo cp -R /var/lib/mysql/* /data/mysql
sudo chown -R mysql:mysql /data/mysql <==Modify the access rights of the new path sudo service mysql stop <==Stop the MySQL service

If it is not a new database, delete the log file

rm -rf /database/mysql/ib_logfile0
rm -rf /database/mysql/ib_logfile1

Modify the /etc/mysql/mysql.conf.d/mysqld.cnf file: datadir = /data/mysql.

Modify the startup file

sudo vim /etc/apparmor.d/usr.sbin.mysqld

Will
/var/lib/mysql/r
/var/lib/mysql/** rwk
Change to
/data/mysql/r
/data/mysql/** rwk

Restart MySQL

sudo /etc/init.d/apparmor restart
sudo /etc/init.d/mysql restart

Log in to MySql and verify the data directory

mysql>show variables like '%dir%'; <==When datadir is displayed as /data/mysql, the modification is successful

As shown in the figure

MySQL is relatively easy to install via APT

The following is a detailed command flow for data file migration, for reference only.

root@ww:~# mkdir /data/mysql
root@ww:~# sudo cp -R /var/lib/mysql/* /data/mysql
root@ww:~# sudo chown -R mysql:mysql /data/mysql
root@ww:~# sudo service mysql stop
root@ww:~# vim /etc/mysql/mysql.conf.d/mysqld.cnf
root@ww:~# sudo vim /etc/apparmor.d/usr.sbin.mysqld
root@ww:~# sudo /etc/init.d/apparmor restart
[ ok ] Restarting apparmor (via systemctl): apparmor.service.
root@ww:~# sudo /etc/init.d/mysql restart
[ ok ] Restarting mysql (via systemctl): mysql.service.

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:
  • Two ways of storing scrapy data in MySQL database (synchronous and asynchronous)
  • Python example of storing JSON-like data in MySQL
  • How to change the database data storage directory in MySQL
  • Detailed example of MySQL data storage process parameters
  • How to move mysql5.7.19 data storage location in Centos7
  • How to implement Mysql switching data storage directory
  • Solution to changing the data storage location of the database in MySQL 5.7
  • MySQL database architecture details
  • MySQL spatial data storage and functions

<<:  MySQL database SELECT query expression analysis

>>:  How to turn local variables into global variables in JavaScript

Recommend

JavaScript type detection method example tutorial

Preface JavaScript is one of the widely used lang...

An article to help you understand the basics of VUE

Table of contents What is VUE Core plugins in Vue...

Detailed explanation of the pitfalls of nginx proxy socket.io service

Table of contents Nginx proxies two socket.io ser...

Introduction to version management tool Rational ClearCase

Rational ClearCase is a software configuration ma...

Zabbix redis automatic port discovery script returns json format

When we perform automatic discovery, there is alw...

Detailed explanation of MySQL three-value logic and NULL

Table of contents What is NULL Two kinds of NULL ...

Solution to 1045 error in mysql database

How to solve the problem of 1045 when the local d...

How to implement CSS mask full screen center alignment

The specific code is as follows: <style> #t...

Detailed explanation of 4 common data sources in Spark SQL

Generic load/write methods Manually specify optio...

Creative About Us Web Page Design

Unique “About”-Pages A great way to distinguish yo...

Vue.js $refs usage case explanation

Despite props and events, sometimes you still nee...

Mysql table creation foreign key error solution

Database Table A: CREATE TABLE task_desc_tab ( id...

Briefly understand the two common methods of creating files in Linux terminal

We all know that we can use the mkdir command to ...