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

Example of how to implement keepalived+nginx high availability

1. Introduction to keepalived Keepalived was orig...

Detailed explanation of the new CSS display:box property

1. display:box; Setting this property on an eleme...

Summary of common commands for Linux user and group management

This article summarizes the common commands for L...

Detailed explanation of fetch network request encapsulation example

export default ({ url, method = 'GET', da...

Four categories of CSS selectors: basic, combination, attribute, pseudo-class

What is a selector? The role of the selector is t...

Solution to Nginx 500 Internal Server Error

Today, when I was using Nginx, a 500 error occurr...

MySQL tutorial data definition language DDL example detailed explanation

Table of contents 1. Introduction to the basic fu...

Insufficient memory problem and solution when docker starts elasticsearch

question Insufficient memory when docker installs...

HTML adaptive table method

<body style="scroll:no"> <tabl...

How to block and prohibit web crawlers in Nginx server

Every website usually encounters many non-search ...

MySQL multi-table join introductory tutorial

Connections can be used to query, update, and est...

JavaScript implements simple scroll window

This article example shares the specific code of ...